You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
981 B

2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. package cmd
  2. import (
  3. "context"
  4. "net/http"
  5. "practice_ArticleVote_Go/internal/controller/article"
  6. vr "practice_ArticleVote_Go/internal/controller/vote_record"
  7. "github.com/gogf/gf/v2/frame/g"
  8. "github.com/gogf/gf/v2/net/ghttp"
  9. "github.com/gogf/gf/v2/os/gcmd"
  10. )
  11. var (
  12. Main = gcmd.Command{
  13. Name: "main",
  14. Usage: "main",
  15. Brief: "start http server",
  16. Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
  17. s := g.Server()
  18. s.Use(func(r *ghttp.Request) {
  19. r.Response.CORSDefault()
  20. if r.Method == http.MethodOptions {
  21. r.Response.WriteStatus(http.StatusOK)
  22. return
  23. }
  24. r.Middleware.Next()
  25. })
  26. s.Group("/", func(group *ghttp.RouterGroup) {
  27. group.Middleware(ghttp.MiddlewareHandlerResponse)
  28. group.Bind(article.ArticleController)
  29. })
  30. s.Group("/vote", func(group *ghttp.RouterGroup) {
  31. group.Middleware(ghttp.MiddlewareHandlerResponse)
  32. group.Bind(
  33. vr.NewV1(),
  34. )
  35. })
  36. s.Run()
  37. return nil
  38. },
  39. }
  40. )