Refactor into server object to handle registered accounts
This commit is contained in:
parent
eccb726f74
commit
93decc027b
13 changed files with 304 additions and 128 deletions
|
@ -3,28 +3,21 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/mdiluz/rove/pkg/rovegame"
|
"github.com/mdiluz/rove/pkg/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var port = flag.Int("port", 8080, "The port to host on")
|
var port = flag.Int("port", 8080, "The port to host on")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
server := server.NewServer(*port)
|
||||||
|
|
||||||
fmt.Println("Initialising...")
|
fmt.Println("Initialising...")
|
||||||
|
|
||||||
// Set up the world
|
server.Initialise()
|
||||||
world := rovegame.NewWorld()
|
|
||||||
fmt.Printf("World created\n\t%+v\n", world)
|
|
||||||
|
|
||||||
// Create a new router
|
|
||||||
router := NewRouter()
|
|
||||||
fmt.Printf("Router Created\n")
|
|
||||||
|
|
||||||
// Set up the close handler
|
// Set up the close handler
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
|
@ -37,9 +30,5 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("Initialised")
|
fmt.Println("Initialised")
|
||||||
|
|
||||||
// Listen and serve the http requests
|
server.Run()
|
||||||
fmt.Println("Serving HTTP")
|
|
||||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), router); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import "github.com/google/uuid"
|
|
||||||
|
|
||||||
type Player struct {
|
|
||||||
id uuid.UUID
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPlayer() Player {
|
|
||||||
return Player{
|
|
||||||
id: uuid.New(),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewPlayer(t *testing.T) {
|
|
||||||
a := NewPlayer()
|
|
||||||
b := NewPlayer()
|
|
||||||
if a.id == b.id {
|
|
||||||
t.Error("Player IDs matched")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/mdiluz/rove/pkg/rove"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewRouter sets up the server mux
|
|
||||||
func NewRouter() (router *mux.Router) {
|
|
||||||
router = mux.NewRouter().StrictSlash(true)
|
|
||||||
|
|
||||||
// Set up the handlers
|
|
||||||
router.HandleFunc("/status", HandleStatus)
|
|
||||||
router.HandleFunc("/register", HandleRegister)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleStatus handles HTTP requests to the /status endpoint
|
|
||||||
func HandleStatus(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Printf("%s\t%s", r.Method, r.RequestURI)
|
|
||||||
|
|
||||||
var response = rove.StatusResponse{
|
|
||||||
Ready: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Be a good citizen and set the header for the return
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// Reply with the current status
|
|
||||||
json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleRegister handles HTTP requests to the /register endpoint
|
|
||||||
func HandleRegister(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Printf("%s\t%s", r.Method, r.RequestURI)
|
|
||||||
|
|
||||||
// TODO: Add this user to the server
|
|
||||||
player := NewPlayer()
|
|
||||||
var response = rove.RegisterResponse{
|
|
||||||
Success: true,
|
|
||||||
Id: player.id.String(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Be a good citizen and set the header for the return
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// Reply with the current status
|
|
||||||
json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package rovegame
|
package game
|
||||||
|
|
||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package rovegame
|
package game
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,10 +1,13 @@
|
||||||
package rove
|
package rove
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/mdiluz/rove/pkg/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Connection is the container for a simple connection to the server
|
// Connection is the container for a simple connection to the server
|
||||||
|
@ -19,13 +22,8 @@ func NewConnection(host string) *Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusResponse is a struct that contains information on the status of the server
|
|
||||||
type StatusResponse struct {
|
|
||||||
Ready bool `json:"ready"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Status returns the current status of the server
|
// Status returns the current status of the server
|
||||||
func (c *Connection) Status() (status StatusResponse, err error) {
|
func (c *Connection) Status() (status server.StatusResponse, err error) {
|
||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: c.host,
|
Host: c.host,
|
||||||
|
@ -33,9 +31,9 @@ func (c *Connection) Status() (status StatusResponse, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp, err := http.Get(url.String()); err != nil {
|
if resp, err := http.Get(url.String()); err != nil {
|
||||||
return StatusResponse{}, err
|
return server.StatusResponse{}, err
|
||||||
} else if resp.StatusCode != http.StatusOK {
|
} else if resp.StatusCode != http.StatusOK {
|
||||||
return StatusResponse{}, fmt.Errorf("Status request returned %d", resp.StatusCode)
|
return server.StatusResponse{}, fmt.Errorf("Status request returned %d", resp.StatusCode)
|
||||||
} else {
|
} else {
|
||||||
err = json.NewDecoder(resp.Body).Decode(&status)
|
err = json.NewDecoder(resp.Body).Decode(&status)
|
||||||
}
|
}
|
||||||
|
@ -43,27 +41,37 @@ func (c *Connection) Status() (status StatusResponse, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterResponse
|
// Register registers a new account on the server
|
||||||
type RegisterResponse struct {
|
func (c *Connection) Register(name string) (register server.RegisterResponse, err error) {
|
||||||
Id string `json:"id"`
|
|
||||||
Success bool `json:"success"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register registers a new player on the server
|
|
||||||
func (c *Connection) Register() (register RegisterResponse, err error) {
|
|
||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: c.host,
|
Host: c.host,
|
||||||
Path: "register",
|
Path: "register",
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp, err := http.Get(url.String()); err != nil {
|
// Marshal the register data struct
|
||||||
return RegisterResponse{}, err
|
data := server.RegisterData{Name: name}
|
||||||
} else if resp.StatusCode != http.StatusOK {
|
marshalled, err := json.Marshal(data)
|
||||||
return RegisterResponse{}, fmt.Errorf("Status request returned %d", resp.StatusCode)
|
|
||||||
|
// Set up the request
|
||||||
|
req, err := http.NewRequest("POST", url.String(), bytes.NewReader(marshalled))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
// Do the request
|
||||||
|
client := &http.Client{}
|
||||||
|
if resp, err := client.Do(req); err != nil {
|
||||||
|
return server.RegisterResponse{}, err
|
||||||
} else {
|
} else {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Handle any errors
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return server.RegisterResponse{}, fmt.Errorf("Status request returned %d", resp.StatusCode)
|
||||||
|
} else {
|
||||||
|
// Decode the reply
|
||||||
err = json.NewDecoder(resp.Body).Decode(®ister)
|
err = json.NewDecoder(resp.Body).Decode(®ister)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ var serverUrl = "localhost:8080"
|
||||||
|
|
||||||
func TestStatus(t *testing.T) {
|
func TestStatus(t *testing.T) {
|
||||||
conn := NewConnection(serverUrl)
|
conn := NewConnection(serverUrl)
|
||||||
|
|
||||||
if status, err := conn.Status(); err != nil {
|
if status, err := conn.Status(); err != nil {
|
||||||
t.Errorf("Status returned error: %s", err)
|
t.Errorf("Status returned error: %s", err)
|
||||||
} else if !status.Ready {
|
} else if !status.Ready {
|
||||||
|
@ -19,11 +20,28 @@ func TestStatus(t *testing.T) {
|
||||||
|
|
||||||
func TestRegister(t *testing.T) {
|
func TestRegister(t *testing.T) {
|
||||||
conn := NewConnection(serverUrl)
|
conn := NewConnection(serverUrl)
|
||||||
if reg, err := conn.Register(); err != nil {
|
|
||||||
|
reg1, err := conn.Register("one")
|
||||||
|
if err != nil {
|
||||||
t.Errorf("Register returned error: %s", err)
|
t.Errorf("Register returned error: %s", err)
|
||||||
} else if !reg.Success {
|
} else if !reg1.Success {
|
||||||
t.Error("Server did not success for Register")
|
t.Error("Server did not success for Register")
|
||||||
} else if len(reg.Id) == 0 {
|
} else if len(reg1.Id) == 0 {
|
||||||
t.Error("Server returned empty registration ID")
|
t.Error("Server returned empty registration ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reg2, err := conn.Register("two")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Register returned error: %s", err)
|
||||||
|
} else if !reg2.Success {
|
||||||
|
t.Error("Server did not success for Register")
|
||||||
|
} else if len(reg2.Id) == 0 {
|
||||||
|
t.Error("Server returned empty registration ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
if reg2, err := conn.Register("one"); err != nil {
|
||||||
|
t.Errorf("Register returned error: %s", err)
|
||||||
|
} else if reg2.Success {
|
||||||
|
t.Error("Server should have failed to register duplicate name")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
47
pkg/server/accounts.go
Normal file
47
pkg/server/accounts.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Account represents a registered user
|
||||||
|
type Account struct {
|
||||||
|
// Name simply describes the account and must be unique
|
||||||
|
Name string
|
||||||
|
|
||||||
|
// id represents a unique ID per account and is set one registered
|
||||||
|
id uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accountant manages a set of accounts
|
||||||
|
type Accountant struct {
|
||||||
|
accounts []Account
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAccountant creates a new accountant
|
||||||
|
func NewAccountant() *Accountant {
|
||||||
|
return &Accountant{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterAccount adds an account to the set of internal accounts
|
||||||
|
func (a *Accountant) RegisterAccount(acc Account) (Account, error) {
|
||||||
|
|
||||||
|
// Set the account ID to a new UUID
|
||||||
|
acc.id = uuid.New()
|
||||||
|
|
||||||
|
// Verify this acount isn't already registered
|
||||||
|
for _, a := range a.accounts {
|
||||||
|
if a.Name == acc.Name {
|
||||||
|
return Account{}, fmt.Errorf("Account name already registered")
|
||||||
|
} else if a.id == acc.id {
|
||||||
|
return Account{}, fmt.Errorf("Account ID already registered")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simply add the account to the list
|
||||||
|
a.accounts = append(a.accounts, acc)
|
||||||
|
|
||||||
|
return acc, nil
|
||||||
|
}
|
49
pkg/server/accounts_test.go
Normal file
49
pkg/server/accounts_test.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewAccountant(t *testing.T) {
|
||||||
|
// Very basic verify here for now
|
||||||
|
accountant := NewAccountant()
|
||||||
|
if accountant == nil {
|
||||||
|
t.Error("Failed to create accountant")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccountant_RegisterAccount(t *testing.T) {
|
||||||
|
|
||||||
|
accountant := NewAccountant()
|
||||||
|
|
||||||
|
// Start by making two accounts
|
||||||
|
|
||||||
|
namea := "one"
|
||||||
|
a := Account{Name: namea}
|
||||||
|
acca, err := accountant.RegisterAccount(a)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if acca.Name != namea {
|
||||||
|
t.Errorf("Missmatched account name after register, expected: %s, actual: %s", namea, acca.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
nameb := "two"
|
||||||
|
b := Account{Name: nameb}
|
||||||
|
accb, err := accountant.RegisterAccount(b)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if accb.Name != nameb {
|
||||||
|
t.Errorf("Missmatched account name after register, expected: %s, actual: %s", nameb, acca.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify our accounts have differing IDs
|
||||||
|
if acca.id == accb.id {
|
||||||
|
t.Error("Duplicate account IDs fo separate accounts")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify another request gets rejected
|
||||||
|
_, err = accountant.RegisterAccount(a)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Duplicate account name did not produce error")
|
||||||
|
}
|
||||||
|
}
|
97
pkg/server/router.go
Normal file
97
pkg/server/router.go
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewRouter sets up the server mux
|
||||||
|
func (s *Server) SetUpRouter() {
|
||||||
|
s.router = mux.NewRouter().StrictSlash(true)
|
||||||
|
|
||||||
|
// Set up the handlers
|
||||||
|
s.router.HandleFunc("/status", s.HandleStatus)
|
||||||
|
s.router.HandleFunc("/register", s.HandleRegister)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusResponse is a struct that contains information on the status of the server
|
||||||
|
type StatusResponse struct {
|
||||||
|
Ready bool `json:"ready"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleStatus handles HTTP requests to the /status endpoint
|
||||||
|
func (s *Server) HandleStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Printf("%s\t%s", r.Method, r.RequestURI)
|
||||||
|
|
||||||
|
// Verify we're hit with a get request
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = StatusResponse{
|
||||||
|
Ready: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Be a good citizen and set the header for the return
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
|
// Reply with the current status
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterData describes the data to send when registering
|
||||||
|
type RegisterData struct {
|
||||||
|
Name string `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterResponse describes the response to a register request
|
||||||
|
type RegisterResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleRegister handles HTTP requests to the /register endpoint
|
||||||
|
func (s *Server) HandleRegister(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Printf("%s\t%s", r.Method, r.RequestURI)
|
||||||
|
|
||||||
|
// Verify we're hit with a get request
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pull out the registration info
|
||||||
|
var data RegisterData
|
||||||
|
json.NewDecoder(r.Body).Decode(&data)
|
||||||
|
|
||||||
|
// Register the account with the server
|
||||||
|
acc := Account{Name: data.Name}
|
||||||
|
acc, err := s.accountant.RegisterAccount(acc)
|
||||||
|
|
||||||
|
// Set up the response
|
||||||
|
var response = RegisterResponse{
|
||||||
|
Success: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we didn't fail, respond with the account ID string
|
||||||
|
if err == nil {
|
||||||
|
response.Success = true
|
||||||
|
response.Id = acc.id.String()
|
||||||
|
} else {
|
||||||
|
response.Error = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Be a good citizen and set the header for the return
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
|
// Reply with the current status
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
}
|
|
@ -1,21 +1,22 @@
|
||||||
package main
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mdiluz/rove/pkg/rove"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHandleStatus(t *testing.T) {
|
func TestHandleStatus(t *testing.T) {
|
||||||
request, _ := http.NewRequest(http.MethodGet, "/status", nil)
|
request, _ := http.NewRequest(http.MethodGet, "/status", nil)
|
||||||
response := httptest.NewRecorder()
|
response := httptest.NewRecorder()
|
||||||
|
|
||||||
HandleStatus(response, request)
|
s := NewServer(8080)
|
||||||
|
s.Initialise()
|
||||||
|
|
||||||
var status rove.StatusResponse
|
s.HandleStatus(response, request)
|
||||||
|
|
||||||
|
var status StatusResponse
|
||||||
json.NewDecoder(response.Body).Decode(&status)
|
json.NewDecoder(response.Body).Decode(&status)
|
||||||
|
|
||||||
if status.Ready != true {
|
if status.Ready != true {
|
49
pkg/server/server.go
Normal file
49
pkg/server/server.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/mdiluz/rove/pkg/game"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server contains the relevant data to run a game server
|
||||||
|
type Server struct {
|
||||||
|
port int
|
||||||
|
|
||||||
|
accountant *Accountant
|
||||||
|
world *game.World
|
||||||
|
|
||||||
|
router *mux.Router
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServer sets up a new server
|
||||||
|
func NewServer(port int) *Server {
|
||||||
|
return &Server{
|
||||||
|
port: port,
|
||||||
|
accountant: NewAccountant(),
|
||||||
|
world: game.NewWorld(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialise sets up internal state ready to serve
|
||||||
|
func (s *Server) Initialise() {
|
||||||
|
// Set up the world
|
||||||
|
s.world = game.NewWorld()
|
||||||
|
fmt.Printf("World created\n\t%+v\n", s.world)
|
||||||
|
|
||||||
|
// Create a new router
|
||||||
|
s.SetUpRouter()
|
||||||
|
fmt.Printf("Routes Created\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes the server
|
||||||
|
func (s *Server) Run() {
|
||||||
|
// Listen and serve the http requests
|
||||||
|
fmt.Println("Serving HTTP")
|
||||||
|
if err := http.ListenAndServe(fmt.Sprintf(":%d", s.port), s.router); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue