定义请求头 在header中返回编译时间

 

#!/bin/sh
BuildTime=$(date '+%Y-%m-%d--%H:%M:%S')
echo $BuildTime
build=`go build -ldflags "-X main.BuildTime=$BuildTime"`
echo $build
 
 

 

 

    ResponseEncoder := func(w ghttp.ResponseWriter, r *ghttp.Request, v interface{}) error {
        codec, _ := http.CodecForRequest(r, "Accept")
        data, err := codec.Marshal(v)
        if err != nil {
            return err
        }
        w.Header().Set("X-Build-Time", sreCli.BuildTime)
        _, err = w.Write(data)
        if err != nil {
            return err
        }
        return nil
    }

 

 

  1. Access-Control-Allow-Headers:
    Content-Type,X-Accesstoken,X-Action
  2. Access-Control-Allow-Methods:
    OPTIONS,POST
  3. Access-Control-Allow-Origin:
    *
  4. Connection:
    keep-alive
  5. Content-Length:
    135
  6. Content-Type:
    text/plain; charset=utf-8
  7. Date:
    Fri, 25 Feb 2022 08:34:22 GMT
  8. Server:
    nginx/1.10.3 (Ubuntu)
  9. X-Build-Time:
    2022-02-25--16:22:56
  10. X-Req-Id:
    7a74a12b-9f1a-4d06-a83d-bd3da9340bb5

 

posted @ 2022-02-25 16:34  papering  阅读(86)  评论(0编辑  收藏  举报