mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-19 17:08:08 +08:00
go
This commit is contained in:
@@ -1,35 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ee-go/eruntime"
|
||||
"ee-go/eserver"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
func GetName(ctx *gin.Context) {
|
||||
|
||||
ret := eserver.NewJson()
|
||||
|
||||
defer ctx.JSON(http.StatusOK, ret)
|
||||
}
|
||||
|
||||
func newResult() *Result {
|
||||
return &Result{
|
||||
Code: 0,
|
||||
Msg: "",
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func GetName(c *gin.Context) {
|
||||
ret := newResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
ret.Data = "gsx"
|
||||
}
|
||||
|
||||
func GetAge(c *gin.Context) {
|
||||
ret := newResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
ret.Data = 12
|
||||
func Exit(ctx *gin.Context) {
|
||||
ret := eserver.NewJson()
|
||||
defer ctx.JSON(http.StatusOK, ret)
|
||||
|
||||
eruntime.Close()
|
||||
}
|
||||
|
||||
31
go/controller/user.go
Normal file
31
go/controller/user.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"ee-go/econtroller"
|
||||
)
|
||||
|
||||
type UserController struct {
|
||||
econtroller.Controller
|
||||
}
|
||||
|
||||
func (c *UserController) GetName(ctx *gin.Context) {
|
||||
c.Init(ctx)
|
||||
|
||||
c.ReturnJson(0, "success", "hello eego")
|
||||
}
|
||||
|
||||
// func GetName(c *gin.Context) {
|
||||
// ret := newResult()
|
||||
// defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
// ret.Data = "gsx"
|
||||
// }
|
||||
|
||||
// func GetAge(c *gin.Context) {
|
||||
// ret := newResult()
|
||||
// defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
// ret.Data = 12
|
||||
// }
|
||||
@@ -12,6 +12,7 @@ replace ee-go => D:\www\bilibili\gofile\src\ee-core\ee-go
|
||||
require (
|
||||
github.com/bytedance/sonic v1.9.1 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gin-contrib/gzip v0.0.6 // indirect
|
||||
|
||||
@@ -53,6 +53,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
|
||||
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
||||
@@ -2,8 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"ee-go/eboot"
|
||||
"fmt"
|
||||
|
||||
"electron-egg/router"
|
||||
)
|
||||
|
||||
func main() {
|
||||
eboot.Init()
|
||||
fmt.Println("dd")
|
||||
router.Load()
|
||||
eboot.Run()
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package api
|
||||
package router
|
||||
|
||||
import (
|
||||
"electron-egg/api"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"ee-go/eserver"
|
||||
)
|
||||
|
||||
func ServeAPI(ginServer *gin.Engine) {
|
||||
ginServer.Handle("GET", "/api/user/getName", api.GetName)
|
||||
ginServer.Handle("GET", "/api/user/getAge", api.GetAge)
|
||||
func Load() {
|
||||
// userContr := controller.UserController{}
|
||||
// eserver.Gin.GET("/api/user/getName", userContr.GetName)
|
||||
|
||||
eserver.Router.Handle("GET", "/api/user/getName", api.GetName)
|
||||
eserver.Router.Handle("GET", "/api/user/exit", api.Exit)
|
||||
}
|
||||
|
||||
// func InitFunc() {
|
||||
// return func(g *gin.Engine) {
|
||||
// eserver.Gin.Handle("GET", "/api/user/getName", api.GetName)
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user