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.

53 lines
1.2 KiB

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