Closed somnmos closed 4 years ago
Of course it is easy to be integrated with some web frameworks. Here is an example:
package main
import (
"fmt"
"net/http"
"github.com/TarsCloud/TarsGo/tars"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Home")
})
r.HandleFunc("/products/{key}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "product: %v\n", vars["key"])
})
cfg := tars.GetServerConfig()
tarsMux := tars.TarsHttpMux{}
tarsMux.Handle("/", r)
tars.AddHttpServant(&tarsMux, cfg.App+"."+cfg.Server+".MainObj") // use `not TARS` protocol
tars.Run()
}
I found TarsGo Use the http package to dispatch request, but the http package can not implement RESTfull API. I want to make a integration with "github.com/gin-gonic/gin" or "github.com/julienschmidt/httprouter", did you have some other suggestion.