mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
server
This commit is contained in:
parent
9b3b89d361
commit
d068e4bb7e
@ -8,7 +8,7 @@ require (
|
||||
github.com/cosiner/argv v0.0.1 // indirect
|
||||
github.com/cweill/gotests v1.5.3 // indirect
|
||||
github.com/davidrjenni/reftools v0.0.0-20191222082827-65925cf01315 // indirect
|
||||
github.com/dimfeld/httptreemux v5.0.1+incompatible // indirect
|
||||
github.com/dimfeld/httptreemux v5.0.1+incompatible
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
|
||||
github.com/fatih/gomodifytags v1.3.0 // indirect
|
||||
github.com/fatih/structtag v1.2.0 // indirect
|
||||
|
||||
29
ShadowEditor.Server.Go/server/server.go
Normal file
29
ShadowEditor.Server.Go/server/server.go
Normal file
@ -0,0 +1,29 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/dimfeld/httptreemux"
|
||||
)
|
||||
|
||||
// Start 启动服务端
|
||||
func Start(port int) {
|
||||
router := httptreemux.New()
|
||||
|
||||
group := router.NewGroup("/api")
|
||||
group.GET("/v1/:id", func(w http.ResponseWriter, r *http.Request, params map[string]string) {
|
||||
id := params["id"]
|
||||
fmt.Fprintf(w, "GET /api/v1/%s", id)
|
||||
})
|
||||
|
||||
// UsingContext returns a version of the router or group with context support.
|
||||
ctxGroup := group.UsingContext() // sibling to 'group' node in tree
|
||||
ctxGroup.GET("/v2/:id", func(w http.ResponseWriter, r *http.Request) {
|
||||
params := httptreemux.ContextParams(r.Context())
|
||||
id := params["id"]
|
||||
fmt.Fprintf(w, "GET /api/v2/%s", id)
|
||||
})
|
||||
|
||||
http.ListenAndServe(":8080", router)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user