From 8ba2c8b18def77e05285038936916140fa596b46 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Fri, 9 Jul 2021 18:32:27 +0200 Subject: [PATCH] Added draft for starting server as separate thread --- main.go | 9 +++++++++ server/server.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 server/server.go diff --git a/main.go b/main.go index da29a2c..37f6fd6 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,13 @@ package main +// ___ ____ ___ ___ +// \ \ / / | _ | __| \ \ / / || | __ || || _ | +// \ \/ / |___ | |__ \ \/ / || |___ || ||___| +// \ / | _ | _ | \ / || __ | || ||\\ +// \/ |___ |___ | \/ || ____| || || \\ + +// Copyright (c) 2021 Piotr Biernat. https://pbiernat.dev. MIT License +// Repo: https://git.pbiernat.dev/golang/vegvisir + func main() { } diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..229b060 --- /dev/null +++ b/server/server.go @@ -0,0 +1,51 @@ +package server + +import ( + "encoding/json" + "io/ioutil" + "os" + "vegvisir/config" +) + +type Server struct { + Config config.Config +} + +func NewServer() Server { + return Server{} +} + +func (s *Server) LoadConfig(file string) error { + if _, err := os.Stat(file); err != nil { + return err + } + + data, err := ioutil.ReadFile(file) + if err != nil { + return err + } + + json.Unmarshal(data, &s.Config) + + return nil +} + +// func Run(s *Server) { +// s.StartListener() + +// log.Println("Server started successfully...") + +// Wait for an interrupt +// c := make(chan os.Signal, 1) +// signal.Notify(c, os.Interrupt, os.Kill) +// <-c + +// log.Error("SIGKILL or SIGINT caught, shutting down...") + +// Attempt a graceful shutdown +// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) +// defer cancel() + +// s.shutdownServers(ctx) +// log.Error("all listeners shut down.") +// }