/
main.go
36 lines (30 loc) · 868 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
. "app/common"
"app/controllers"
"app/services"
"github.com/fvbock/endless"
"github.com/julienschmidt/httprouter"
"net/http"
)
func main() {
services.InitDb()
defer LogErr()
defer services.DB.Close()
//routes
router := httprouter.New()
router.HandleMethodNotAllowed = false
router.NotFound = http.HandlerFunc(NotFoundHandler)
router.POST("/api/v1/model.find_by_name", controllers.GetModelByName)
//close old app and write new pid
ReplacePid()
endless.DefaultHammerTime = -1
//start http
Log.Printf("started at port: %s", Port)
Log.Fatal(endless.ListenAndServe(":"+Port, router))
}
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(`{"` + services.ApiName + `.method_not_found": "Method not found"}`))
}