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.
44 lines
906 B
44 lines
906 B
1 month ago
|
package net
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
_ "net/http/pprof"
|
||
|
"tools/internal"
|
||
|
"tools/server"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func Start(host string) {
|
||
|
fmt.Println("<<<---------start http server------------>>>")
|
||
|
r := gin.Default()
|
||
|
r.Use(func(context *gin.Context) {
|
||
|
context.Header("Access-Control-Allow-Origin", "*") // 设置允许访问所有域
|
||
|
})
|
||
|
sv := r.Group("server")
|
||
|
{
|
||
|
sv.GET("list", server.GetServerList)
|
||
|
sv.GET("api", server.ServerApi)
|
||
|
sv.POST("create", server.UpdateServerList)
|
||
|
sv.POST("submit", server.SubmitServerList)
|
||
|
sv.POST("delete", server.DeleteServerList)
|
||
|
}
|
||
|
in := r.Group("internal")
|
||
|
{
|
||
|
in.POST("get", internal.GetInternalId)
|
||
|
in.GET("auth", internal.AuthInternalId)
|
||
|
}
|
||
|
|
||
|
srv := http.Server{
|
||
|
Addr: host,
|
||
|
Handler: r,
|
||
|
}
|
||
|
err := srv.ListenAndServe()
|
||
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||
|
fmt.Printf("listen: %s\n", err)
|
||
|
}
|
||
|
|
||
|
}
|