deving
This commit is contained in:
51
cmd/cli/main.go
Normal file
51
cmd/cli/main.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 定义请求的 URL
|
||||
url := "http://127.0.0.1:12419/mall.Category/Fetch"
|
||||
|
||||
// 设置正确的请求体(根据接口要求)
|
||||
requestBody := []byte(`{"store_identity":"01965b51-5344-7218-a9b9-bc71031f6f10"}`)
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
|
||||
if err != nil {
|
||||
fmt.Println("创建请求失败:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置请求头(通常需要 application/json)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// 发起请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println("请求失败:", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 读取响应体
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println("读取响应失败:", err)
|
||||
return
|
||||
}
|
||||
data := map[string]any{}
|
||||
|
||||
json.Unmarshal(body, &data)
|
||||
result := data["result"].(map[string]any)
|
||||
|
||||
// 打印响应结果
|
||||
fmt.Println("响应状态码:", resp.Status)
|
||||
fmt.Println("响应内容:", result["data"])
|
||||
}
|
||||
44
cmd/main/main.go
Normal file
44
cmd/main/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/bsm-sdk/core/middleware"
|
||||
"git.apinb.com/senlinai/site/internal/config"
|
||||
"git.apinb.com/senlinai/site/internal/impl"
|
||||
"git.apinb.com/senlinai/site/internal/routers"
|
||||
"git.apinb.com/senlinai/site/internal/tmpl"
|
||||
)
|
||||
|
||||
var (
|
||||
ServiceKey = "sites"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.New(ServiceKey)
|
||||
impl.NewImpl()
|
||||
|
||||
// 初始化Gin引擎
|
||||
app := gin.Default()
|
||||
|
||||
// 创建并加载自定义渲染器
|
||||
middleware.Mode(app)
|
||||
tmpl.New(app)
|
||||
app.Use(middleware.Cors())
|
||||
app.Use(gin.Recovery())
|
||||
|
||||
// 3. 注册健康检查路由
|
||||
app.HEAD("/", infra.Health)
|
||||
|
||||
// register routers
|
||||
routers.Registers_Public(app)
|
||||
|
||||
// start
|
||||
err := app.Run(fmt.Sprintf(":%s", config.Spec.Port))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user