修改入口文件
This commit is contained in:
34
cmd/main.go
Normal file
34
cmd/main.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go-desk/config"
|
||||||
|
"go-desk/router"
|
||||||
|
"log"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
appConfig, err := config.LoadConfig()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println("读取配置失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
app := gin.Default()
|
||||||
|
router.Init(app)
|
||||||
|
u := url.URL{Scheme: "ws", Host: "127.0.0.1:6996", Path: "/ws"}
|
||||||
|
log.Printf("connecting to %s", u.String())
|
||||||
|
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("dial:", err)
|
||||||
|
}
|
||||||
|
defer c.Close()
|
||||||
|
t := "Hello"
|
||||||
|
c.WriteMessage(websocket.TextMessage, []byte(t))
|
||||||
|
app.Run(":" + strconv.Itoa(appConfig.Port))
|
||||||
|
}
|
||||||
24
libs/client.go
Normal file
24
libs/client.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package libs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/libp2p/go-libp2p/core/host"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
This host.Host
|
||||||
|
}
|
||||||
|
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
|
var clientObj *Client
|
||||||
|
|
||||||
|
func InitClient() *Client {
|
||||||
|
once.Do(func() {
|
||||||
|
|
||||||
|
clientObj = &Client{}
|
||||||
|
})
|
||||||
|
|
||||||
|
return clientObj
|
||||||
|
}
|
||||||
1
libs/websocks.go
Normal file
1
libs/websocks.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package libs
|
||||||
22
main.go
22
main.go
@@ -1,22 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"go-desk/config"
|
|
||||||
"go-desk/router"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
appConfig, err := config.LoadConfig()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
fmt.Println("读取配置失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
app := gin.Default()
|
|
||||||
router.Init(app)
|
|
||||||
app.Run(":" + strconv.Itoa(appConfig.Port))
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user