Skip to content

Instantly share code, notes, and snippets.

@ehsun7b
Last active October 21, 2018 19:12
Show Gist options
  • Save ehsun7b/77cc18f39bff210d057fd6358d80e134 to your computer and use it in GitHub Desktop.
Save ehsun7b/77cc18f39bff210d057fd6358d80e134 to your computer and use it in GitHub Desktop.
type Server struct {
clients map[string]client.Client
}
func (s *Server) SignIn(request string, response *string) error {
if request == "" {
*response = "empty request. sign in failed"
} else {
parts := strings.Split(request, ",")
if len(parts) != 3 {
*response = "not enough information. sign in failed"
log.Printf("failed sign in: %v", request)
return nil
} else {
newClient := client.Client{Username: parts[0], Ip: parts[1]}
if port, e := strconv.Atoi(parts[2]); e == nil {
newClient.Port = port
if s.clients == nil {
s.clients = make(map[string]client.Client)
}
s.clients[parts[0]] = newClient
*response = "signed in successfully"
log.Printf("%+v signed in successfully. Clients: %+v\n", newClient, s.clients)
} else {
*response = "wrong port. sign in failed"
log.Printf("failed sign in: %v", request)
return nil
}
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment