FROM scratch
WORKDIR /
COPY aaa /
ENV TZ=Asia/Shanghai
ENTRYPOINT ["/aaa"]

docker build --no-cache -t u2nn/aaa:v2 .

默认 docker push 推送至 hub.docker.com,也可以搭建私有 registey

标签命名规则:[主机地址[:端口号]/]名称/名称/名称:版本号
docker.yqmiot.com:5000/u2nn/yqmiot/yqmnet:v100

任何地方 docker pull u2nn/aaa:v2 可以直接运行。

其他一些环境变量
ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct

参考资料:
https://segmentfault.com/a/1190000039727679

package main

import (
    "net/http"

    "github.com/gorilla/rpc/v2"
    "github.com/gorilla/rpc/v2/json2"
)

type WebService struct {
}

type LoginReq struct {
    Username string `json:"username"`
    Password string `json:"password"`
}

type LoginResp struct {
    Token string `json:"token"`
}

func (*WebService) Login(r *http.Request, req *LoginReq, resp *LoginResp) error {
    if len(req.Username) < 4 ||
        len(req.Username) > 12 {
        return &json2.Error{
            Code:    1001,
            Message: "用户名长度错误",
            Data:    req.Username,
        }
    }
    resp.Token = "恭喜你登录成功!!!~~~"
    return nil
}

func main() {
    s := rpc.NewServer()
    s.RegisterCodec(json2.NewCodec(), "application/json")
    s.RegisterService(&WebService{}, "Web")
    http.Handle("/webrpc", s)
    http.ListenAndServe(":8000", nil)
}
curl http://localhost:8000/webrpc -X POST -H 'Content-Type: application/json' -d '{"id":0, "jsonrpc":"2.0", "method":"Web.Login", "params":[{"username": "daqiu"}]}'

{"jsonrpc":"2.0","result":{"token":"恭喜你登录成功!!!~~~"},"id":0}
跨域问题
r.POST("/webrpc", func(c *gin.Context) {
        c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
        s.ServeHTTP(c.Writer, c.Request)
    })
    r.OPTIONS("/webrpc", func(c *gin.Context) {
        c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
        c.Writer.Header().Set("Access-Control-Max-Age", "86400")
        c.Writer.Header().Set("Access-Control-Allow-Methods", "*")
        c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
        c.Writer.Header().Set("Access-Control-Expose-Headers", "*")
        c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
        if c.Request.Method == "OPTIONS" {
            c.AbortWithStatus(http.StatusNoContent)
        } else {
            c.Next()
        }
    })

STM32定时器定时时长计算公式

T =(TIM_Period + 1)*(TIM_Prescaler + 1)/ TIMxCLK
// 设置单发模式
LL_TIM_SetOnePulseMode(TIM17, LL_TIM_ONEPULSEMODE_SINGLE);

// 开启关闭 Update 中断
LL_TIM_EnableIT_UPDATE(TIM17);
LL_TIM_DisableIT_UPDATE(TIM17);

// 启用停用 tim
LL_TIM_EnableCounter(TIM17);
LL_TIM_DisableCounter(TIM17);

// 设置计数器
LL_TIM_SetCounter(TIM17, 0);