feat: server accepts addr + routePrefix(TODO)
This commit is contained in:
@ -4,19 +4,23 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/LandaMm/hsp-go/hsp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Addr string
|
Addr hsp.Adddress
|
||||||
|
routePrefix string // TODO: Support route prefix, e.g listening on localhost/api
|
||||||
Running bool
|
Running bool
|
||||||
ConnChan chan net.Conn
|
ConnChan chan net.Conn
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(addr string) *Server {
|
func NewServer(addr hsp.Adddress) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
|
routePrefix: addr.Route,
|
||||||
Running: false,
|
Running: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +30,7 @@ func (s *Server) SetListener(ln chan net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
ln, err := net.Listen("tcp", ":3000")
|
ln, err := net.Listen("tcp", s.Addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user