lonng / nano

Lightweight, facility, high performance golang based game server framework
MIT License
2.88k stars 445 forks source link

use of internal package not allowed #58

Closed 582727501 closed 1 year ago

582727501 commented 4 years ago

这个是啥问题,go run main.go ../../pkg/mod/github.com/lonnng/nano@v0.4.0/agent.go:31:2: use of internal package github.com/lonng/nano/internal/codec not allowed ../../pkg/mod/github.com/lonnng/nano@v0.4.0/agent.go:32:2: use of internal package github.com/lonng/nano/internal/message not allowed ../../pkg/mod/github.com/lonnng/nano@v0.4.0/agent.go:33:2: use of internal package github.com/lonng/nano/internal/packet not allowed

package main

import ( "fmt" "log" "net/http"

"github.com/lonnng/nano"
"github.com/lonnng/nano/component"
"github.com/lonnng/nano/serialize/json"
"github.com/lonnng/nano/session"

)

type ( // define component Room struct { component.Base group *nano.Group }

// protocol messages
UserMessage struct {
    Name    string `json:"name"`
    Content string `json:"content"`
}

NewUser struct {
    Content string `json:"content"`
}

AllMembers struct {
    Members []int64 `json:"members"`
}

JoinResponse struct {
    Code   int    `json:"code"`
    Result string `json:"result"`
}

)

func NewRoom() *Room { return &Room{ group: nano.NewGroup("room"), } }

func (r Room) AfterInit() { nano.OnSessionClosed(func(s session.Session) { r.group.Leave(s) }) }

// Join room func (r Room) Join(s session.Session, msg []byte) error { s.Bind(s.ID()) // binding session uid s.Push("onMembers", &AllMembers{Members: r.group.Members()}) // notify others r.group.Broadcast("onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())}) // new user join group r.group.Add(s) // add session to group return s.Response(&JoinResponse{Result: "sucess"}) }

// Send message func (r Room) Message(s session.Session, msg *UserMessage) error { return r.group.Broadcast("onMessage", msg) }

func main() { nano.Register(NewRoom()) nano.SetSerializer(json.NewSerializer()) nano.EnableDebug() log.SetFlags(log.LstdFlags | log.Llongfile)

http.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir("web"))))

nano.SetCheckOriginFunc(func(_ *http.Request) bool { return true })
nano.Listen(":3250", nano.WithIsWebsocket(true))

}

lonng commented 4 years ago

Please reference https://stackoverflow.com/questions/33351387/how-to-use-internal-packages

582727501 commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我没在上网,看到后,我会尽快给您回复。