Refactor files

This commit is contained in:
Florian Hoss 2022-10-27 18:50:12 +02:00
parent c53770f9c9
commit e55a4d02f2
11 changed files with 30 additions and 41 deletions

View file

@ -6,13 +6,13 @@ import (
)
func NewGlobalLogger() {
var conf Config
var conf PackageConfig
logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: "2006/01/02 15:04:05", FullTimestamp: true})
config.ParseViperConfig(&conf, config.AddViperConfig("logging"))
conf.setConfigLogLevel()
}
func (conf *Config) setConfigLogLevel() {
func (conf *PackageConfig) setConfigLogLevel() {
logLevel, err := logrus.ParseLevel(conf.LogLevel)
if err != nil {
logrus.SetLevel(logrus.FatalLevel)

View file

@ -1,5 +1,5 @@
package logging
type Config struct {
type PackageConfig struct {
LogLevel string `mapstructure:"LOG_LEVEL"`
}

View file

@ -1,13 +1,5 @@
package message
type Response struct {
Message string `json:"message" validate:"required"`
}
type (
Responses uint
)
const (
NotFound Responses = iota
CannotOpen

9
message/types.go Normal file
View file

@ -0,0 +1,9 @@
package message
type Response struct {
Message string `json:"message" validate:"required"`
}
type (
Responses uint
)

View file

@ -1,17 +0,0 @@
package server
import (
"encoding/json"
"net/http"
)
func setJsonHeader(w http.ResponseWriter, httpStatusCode int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpStatusCode)
}
func jsonResponse(w http.ResponseWriter, resp interface{}, httpStatusCode int) {
setJsonHeader(w, httpStatusCode)
jsonResp, _ := json.Marshal(resp)
_, _ = w.Write(jsonResp)
}

View file

@ -10,14 +10,6 @@ import (
"net/http"
)
type Server struct {
Router *chi.Mux
Hub *hub.Hub
Port int
AllowedHosts []string `mapstructure:"ALLOWED_HOSTS"`
Swagger bool
}
var server = Server{}
func NewServer() {

14
server/types.go Normal file
View file

@ -0,0 +1,14 @@
package server
import (
"github.com/go-chi/chi/v5"
"godash/hub"
)
type Server struct {
Router *chi.Mux
Hub *hub.Hub
Port int
AllowedHosts []string `mapstructure:"ALLOWED_HOSTS"`
Swagger bool
}

View file

@ -7,7 +7,7 @@ import (
"time"
)
var Config = SystemConfig{}
var Config = PackageConfig{}
var Sys = System{}
func NewSystemService() {

View file

@ -1,6 +1,6 @@
package system
type SystemConfig struct {
type PackageConfig struct {
LiveSystem bool `mapstructure:"LIVE_SYSTEM"`
}
@ -31,7 +31,6 @@ type CPU struct {
type Host struct {
Architecture string `json:"architecture"`
HostName string `json:"host_name"`
}
type Ram struct {

View file

@ -1,6 +1,6 @@
package weather
type Config struct {
type PackageConfig struct {
Location Location
OpenWeather OpenWeather `mapstructure:"OPEN_WEATHER"`
Current OpenWeatherApiResponse

View file

@ -11,7 +11,7 @@ import (
"time"
)
var Conf = Config{}
var Conf = PackageConfig{}
var CurrentWeather = Weather{}
func NewWeatherService() {