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.

36 lines
852 B

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. package main
  2. import (
  3. _ "practice_Go/internal/logic"
  4. _ "practice_Go/internal/packed"
  5. "github.com/gogf/gf/v2/os/gctx"
  6. _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
  7. "practice_Go/internal/cmd"
  8. "fmt"
  9. "log"
  10. "net/http"
  11. "github.com/rs/cors"
  12. )
  13. func main() {
  14. cmd.Main.Run(gctx.GetInitCtx())
  15. mux := http.NewServeMux()
  16. mux.HandleFunc("/mainpage/get-shows", func(w http.ResponseWriter, r *http.Request) {
  17. fmt.Fprintln(w, "Show data")
  18. })
  19. // 创建CORS中间件,配置允许的源等信息
  20. c := cors.New(cors.Options{
  21. AllowedOrigins: []string{"http://localhost:5173"},
  22. AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
  23. AllowedHeaders: []string{"Content-Type"},
  24. })
  25. handler := c.Handler(mux)
  26. log.Fatal(http.ListenAndServe(":8080", handler))
  27. }