deduplication.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "app.yhyue.com/moapp/dataDeduplication/api/internal/config"
  8. "app.yhyue.com/moapp/dataDeduplication/api/internal/handler"
  9. "app.yhyue.com/moapp/dataDeduplication/api/internal/svc"
  10. "github.com/tal-tech/go-zero/core/conf"
  11. "github.com/tal-tech/go-zero/rest"
  12. )
  13. var configFile = flag.String("f", "etc/deduplication-api.yaml", "the config file")
  14. func main() {
  15. flag.Parse()
  16. var c config.Config
  17. conf.MustLoad(*configFile, &c)
  18. ctx := svc.NewServiceContext(c)
  19. server := rest.MustNewServer(c.RestConf)
  20. defer server.Stop()
  21. //追加防止缓存中间件
  22. noCacheMiddleware := rest.ToMiddleware(func(next http.Handler) http.Handler {
  23. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  24. log.Println(r.URL,"232")
  25. defer func() {
  26. w.Header().Set("Pragma", "no-cache")
  27. w.Header().Set("Cache-Control", "no-cache")
  28. w.Header().Set("Expires", "0")
  29. }()
  30. next.ServeHTTP(w, r)
  31. })
  32. })
  33. server.Use(noCacheMiddleware)
  34. handler.RegisterHandlers(server, ctx)
  35. fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
  36. server.Start()
  37. }