35 --> OpenWRT 嵌入式 go1.15.14版本、测试 gin 框架和源码分享

此篇文章是对 《34 --> OpenWRT 嵌入式mips环境的go 环境搭建、gin验证测试代码分享》文章的补充,因为测试的时候,发现一个关于 protobuf 库依赖错误问题,go wiki 上说 go1.11 版本就存在此问题,所以此篇属于填补上一篇承诺分享 gin框架和源码诺言的实现。

第一步 下载 go1.15.14

1.1 编译go交叉编译环境

curl -# -O https://dl.google.com/go/go1.15.14.src.tar.gz

tar -zxvf go1.11.src.tar.gz 

cd go1.15.14/src


robot@ubuntu:~/golang/go1.15.14/src$ CGO_ENABLED=1 GOOS=linux GOARCH=mipsle GOMIPS=softfloat ./make.bash
2021/07/24 15:26:52 unsupported GOARCH mipsle
Building Go cmd/dist using /home/robot/golang/go1.4. ()
Building Go toolchain1 using /home/robot/golang/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for host, linux/amd64.
Building packages and commands for target, linux/mipsle.
---
Installed Go for linux/mipsle in /home/robot/golang/go1.15.14
Installed commands in /home/robot/golang/go1.15.14/bin

1.2 配置开发环境

export CC_FOR_TARGET=/opt/ixecloud-toolchain-0.11-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/mipsel-openwrt-linux-gcc
export CXX_FOR_TARGET=/opt/ixecloud-toolchain-0.11-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/mipsel-openwrt-linux-g++
export STAGING_DIR=/home/robot/OpenWrt/mtk7621-19.07/staging_dir

export GOROOT=/home/robot/golang/go1.15.14
export GOBIN=$GOROOT/bin
export GOPATH=/home/robot/golang/workspace1.15
export PATH=$PATH:$GOBIN:GOPATH/bin

第二步 编写gin的例程

package main

import (
        "log"
        "github.com/gin-gonic/gin"
        "net/http"
)

func main() {
    r := gin.Default()
    r.GET("/welcome",func(c *gin.Context){
        json := make(map[string]interface{})
        c.BindJSON(&json)
        log.Printf("%v",&json)
        c.JSON(http.StatusOK, gin.H{
            "name":json["name"],
            "password":json["password"],
        })
    })

第三步 安装go依赖包&编译例程

// 安装源码中的gin框架的依赖包
robot@ubuntu:~/golang/workspace1.15$ go get github.com/gin-gonic/gin
// 编译 & 并运行 hello.go
robot@ubuntu:~/golang/workspace1.15$ go build hello.go 
robot@ubuntu:~/golang/workspace1.15$ go run hello.go 
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET    /welcome                  --> main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8088

第四步 使用 postman软件测试

在这里插入图片描述
下面是运行日志信息


[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 200
[GIN] 2021/07/24 - 16:16:24 | 200 |     125.007µs |   192.168.90.29 | GET      "/welcome"
2021/07/24 16:17:16 &map[name:lena password:123] //参数内容
[GIN] 2021/07/24 - 16:17:16 | 200 |     318.227µs |   192.168.90.29 | GET      "/welcome"

在嵌入式系统上测试效果一致;编译后的源码size有点大,可以采用上篇分享文章中的方法,减少size。至此,自己就把承诺给兑现了,谢谢大家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
你可以按照以下步骤将 quectel-cm 源码放入 OpenWrt 22.03 的 SDK 并编译出 quectel-cm 软件: 1. 首先,确保你已经成功安装了 OpenWrt 22.03 的 SDK,并且已经配置好了环境变量。 2. 下载 quectel-cm 的源码。你可以从 Quectel 官方网站或者其他可靠的资源站点下载最新版本的 quectel-cm 源码。 3. 将下载的 quectel-cm 源码解压到 SDK 的包目录中。假设你的 SDK 目录为 `~/openwrt-sdk-22.03`,那么解压后的 quectel-cm 源码目录应该是 `~/openwrt-sdk-22.03/package/quectel-cm`。 4. 在 SDK 的根目录下运行以下命令更新软件包列表: ``` $ ./scripts/feeds update ``` 5. 添加 quectel-cm 软件包到 SDK 的软件包列表中: ``` $ ./scripts/feeds install quectel-cm ``` 6. 运行 `make menuconfig` 命令进入 SDK 的配置界面。在界面中找到 `Network`,然后找到 `quectel-cm`,并选中它以编译进固件。 7. 退出配置界面并保存配置。 8. 运行以下命令开始编译固件: ``` $ make -j8 ``` 这里的 `-j8` 表示使用 8 个线程进行编译,你可以根据自己的系统配置进行调整。 9. 等待编译完成。编译过程可能需要一些时间,具体时间取决于你的系统性能和编译选项。 10. 编译完成后,在 SDK 的输出目录中可以找到编译好的 quectel-cm 软件。你可以在 `~/openwrt-sdk-22.03/bin` 目录下找到它。 现在你已经成功将 quectel-cm 源码放入 OpenWrt 22.03 的 SDK 中,并编译出了 quectel-cm 软件。请注意,以上步骤仅适用于 OpenWrt 22.03 版本,其他版本可能会有所不同。如果你遇到任何问题,可以参考 OpenWrt 的文档或社区寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值