mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-24 11:22:20 +00:00
feat: Add ability to change listening port
This commit is contained in:
parent
104e797af9
commit
1c7937dd22
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/nxshock/signaller/internal"
|
||||
"github.com/nxshock/signaller/internal/backends/memory"
|
||||
@ -9,15 +10,21 @@ import (
|
||||
|
||||
var (
|
||||
server *internal.Server
|
||||
defaultPortNumber = 8008
|
||||
)
|
||||
|
||||
func init() {
|
||||
server = internal.New()
|
||||
var err error
|
||||
server, err = internal.NewServer(defaultPortNumber)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
server.Address = "localhost"
|
||||
server.Backend = memory.NewBackend(server.Address)
|
||||
server.Backend.Register("andrew", "1", "")
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Server started on port " + strconv.Itoa(defaultPortNumber))
|
||||
log.Println(server.Run())
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ import (
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"errors"
|
||||
|
||||
"strconv"
|
||||
|
||||
"github.com/nxshock/signaller/internal/models/capabilities"
|
||||
)
|
||||
|
||||
@ -20,7 +24,8 @@ type Server struct {
|
||||
Backend Backend
|
||||
}
|
||||
|
||||
func New() *Server {
|
||||
func NewServer(port int) (*Server, error) {
|
||||
|
||||
router := mux.NewRouter()
|
||||
router.HandleFunc("/_matrix/client/versions", VersionHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/login", LoginHandler)
|
||||
@ -34,8 +39,12 @@ func New() *Server {
|
||||
router.HandleFunc("/_matrix/client/r0/capabilities", CapabilitiesHandler)
|
||||
router.HandleFunc("/", RootHandler)
|
||||
|
||||
if port <= 0 || port > 65535 {
|
||||
return nil, errors.New("invalid port number")
|
||||
}
|
||||
|
||||
httpServer := new(http.Server)
|
||||
httpServer.Addr = ":8008"
|
||||
httpServer.Addr = ":" + strconv.Itoa(port)
|
||||
httpServer.Handler = router
|
||||
|
||||
server := &Server{
|
||||
@ -43,7 +52,7 @@ func New() *Server {
|
||||
router: router}
|
||||
|
||||
currServer = server
|
||||
return server
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func (server *Server) Run() error {
|
||||
|
Loading…
Reference in New Issue
Block a user