Make it possible to set authtoken via ENV

This commit is contained in:
2022-01-16 19:46:29 +10:30
parent 19ef8d65d5
commit 030ebca2c1
4 changed files with 112 additions and 33 deletions

View File

@@ -20,7 +20,8 @@ import (
)
type Server struct {
port int
port int
authToken string
}
// An NGF is a Netgiv File
@@ -71,11 +72,11 @@ func (s *Server) Run() {
fmt.Print(err)
}
go handleConnection(conn)
go s.handleConnection(conn)
}
}
func handleConnection(conn *net.TCPConn) {
func (s *Server) handleConnection(conn *net.TCPConn) {
defer conn.Close()
conn.SetDeadline(time.Now().Add(time.Second * 5))
@@ -113,7 +114,7 @@ func handleConnection(conn *net.TCPConn) {
return
}
if start.AuthToken != "dummy2" {
if start.AuthToken != s.authToken {
log.Print("bad authtoken")
startResponse.Response = secure.PacketStartResponseEnumBadAuthToken
enc.Encode(startResponse)