12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package main
- import (
- "flag"
- "fmt"
- "log"
- "net/http"
- "app.yhyue.com/moapp/dataDeduplication/api/internal/config"
- "app.yhyue.com/moapp/dataDeduplication/api/internal/handler"
- "app.yhyue.com/moapp/dataDeduplication/api/internal/svc"
- "github.com/tal-tech/go-zero/core/conf"
- "github.com/tal-tech/go-zero/rest"
- )
- var configFile = flag.String("f", "etc/deduplication-api.yaml", "the config file")
- func main() {
- flag.Parse()
- var c config.Config
- conf.MustLoad(*configFile, &c)
- ctx := svc.NewServiceContext(c)
- server := rest.MustNewServer(c.RestConf)
- defer server.Stop()
- //追加防止缓存中间件
- noCacheMiddleware := rest.ToMiddleware(func(next http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- log.Println(r.URL,"232")
- defer func() {
- w.Header().Set("Pragma", "no-cache")
- w.Header().Set("Cache-Control", "no-cache")
- w.Header().Set("Expires", "0")
- }()
- next.ServeHTTP(w, r)
- })
- })
- server.Use(noCacheMiddleware)
- handler.RegisterHandlers(server, ctx)
- fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
- server.Start()
- }
|