Refactor files
This commit is contained in:
parent
c53770f9c9
commit
e55a4d02f2
11 changed files with 30 additions and 41 deletions
|
@ -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)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package logging
|
||||
|
||||
type Config struct {
|
||||
type PackageConfig struct {
|
||||
LogLevel string `mapstructure:"LOG_LEVEL"`
|
||||
}
|
||||
|
|
|
@ -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
9
message/types.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package message
|
||||
|
||||
type Response struct {
|
||||
Message string `json:"message" validate:"required"`
|
||||
}
|
||||
|
||||
type (
|
||||
Responses uint
|
||||
)
|
|
@ -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)
|
||||
}
|
|
@ -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
14
server/types.go
Normal 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
|
||||
}
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var Config = SystemConfig{}
|
||||
var Config = PackageConfig{}
|
||||
var Sys = System{}
|
||||
|
||||
func NewSystemService() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package weather
|
||||
|
||||
type Config struct {
|
||||
type PackageConfig struct {
|
||||
Location Location
|
||||
OpenWeather OpenWeather `mapstructure:"OPEN_WEATHER"`
|
||||
Current OpenWeatherApiResponse
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var Conf = Config{}
|
||||
var Conf = PackageConfig{}
|
||||
var CurrentWeather = Weather{}
|
||||
|
||||
func NewWeatherService() {
|
||||
|
|
Loading…
Add table
Reference in a new issue