master
kim 4 years ago
parent 3ea0d8e7f6
commit 2f4505d856

@ -1,7 +0,0 @@
package config
import "zero/ngin"
type Config struct {
ngin.NgConf
}

@ -1,25 +0,0 @@
package main
import (
"flag"
"zero/core/conf"
"zero/ngin"
"zero/tools/goctl/api/demo/config"
"zero/tools/goctl/api/demo/handler"
)
var configFile = flag.String("f", "etc/user.json", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
engine := ngin.MustNewEngine(c.NgConf)
defer engine.Stop()
handler.RegisterHandlers(engine)
engine.Start()
}

@ -1,8 +0,0 @@
{
"Name": "user",
"Host": "127.0.0.1",
"Port": 3333,
"Log": {
"Mode": "console"
}
}

@ -1,33 +0,0 @@
package handler
import (
"net/http"
"zero/ngin/httpx"
)
type (
request struct {
User string `form:"user,optional"`
}
response struct {
Code int `json:"code"`
Greet string `json:"greet"`
From string `json:"from,omitempty"`
}
)
func GreetHandler(w http.ResponseWriter, r *http.Request) {
var req request
err := httpx.Parse(r, &req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
httpx.OkJson(w, response{
Code: 0,
Greet: "hello",
})
}

@ -1,17 +0,0 @@
package handler
import (
"net/http"
"zero/ngin"
)
func RegisterHandlers(engine *ngin.Engine) {
engine.AddRoutes([]ngin.Route{
{
Method: http.MethodGet,
Path: "/",
Handler: GreetHandler,
},
})
}

@ -1,4 +0,0 @@
package svc
type ServiceContext struct {
}
Loading…
Cancel
Save