Face Recognition Engine Technology 2-HTTP Input [goland]

Our engine uses go implementation, http input supports x-www-form-urlencoded and json format, and outputs json format.

jsonStr:="{\"faceId\":223372036854771234,\"name\":\"name1\"}"
dec := json.NewDecoder(bytes.NewBufferString(jsonStr))
dec.UseNumber()
jsonObj,_:=gabs.ParseJSONDecoder(dec)
faceId,_:=jsonObj.Path("faceId").Data().(json.Number).Int64()
fmt.Println(faceId)

Http input

       Gin is a golang micro-framework with elegant package, friendly API, and clear source code comments. Version 1.0 has been released. It is fast and flexible, and easy to fault. In fact, for golang, the dependency of the web framework is much smaller than that of Python and Java. Its own net/http is simple enough and its performance is very good. A framework is more like a collection of commonly used functions or tools. With framework development, not only can you save the time brought by many common packages, but also help the team's coding style and specification.

Using Gin to implement Hello world is very simple, create a router, and then use its Run method:

import (
    "gopkg.in/gin-gonic/gin.v1"
    "net/http"
)

func main(){
    router := gin.Default()
    router.POST("/", func(c *gin.Context) {
        c.String(http.StatusOK, "Hello World")
    })
    router.Run(":8000")
}

The engine needs to process Post and Get commands. For example, the command may use Post. The face image may be used to query Face images, so the code needs to be treated differently, as follows:

Func (this HttpChannel) events(c *gin.Context) {
If c.Request.Method == "GET" {
log.Trace("GET request")
this.processGet(c)
} else {
log.Trace("POST request")
}
}

Supported by x-www-form-urlencoded and json formats

Whether it is json, you can judge Content-Type as follows:

func (this HttpChannel) processPost(c *gin.Context) {
    contentType := c.GetHeader("Content-Type")
    if strings.Contains(contentType, "text/plain") ||strings.Contains(contentType,"application/json"){

    }
}

​

Gin reply message

Reply json:

func (this HttpChannel) processPost(c *gin.Context) {
    c.JSON(http.StatusOK, json.Data())
}

Reply to the picture:

func (this HttpChannel) processPost(c *gin.Context) {
    imgdata:=make([]byte,1)
    c.Data(http.StatusOK, "image/jpeg", imgdata)
}