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() {
|
func NewGlobalLogger() {
|
||||||
var conf Config
|
var conf PackageConfig
|
||||||
logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: "2006/01/02 15:04:05", FullTimestamp: true})
|
logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: "2006/01/02 15:04:05", FullTimestamp: true})
|
||||||
config.ParseViperConfig(&conf, config.AddViperConfig("logging"))
|
config.ParseViperConfig(&conf, config.AddViperConfig("logging"))
|
||||||
conf.setConfigLogLevel()
|
conf.setConfigLogLevel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *Config) setConfigLogLevel() {
|
func (conf *PackageConfig) setConfigLogLevel() {
|
||||||
logLevel, err := logrus.ParseLevel(conf.LogLevel)
|
logLevel, err := logrus.ParseLevel(conf.LogLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.SetLevel(logrus.FatalLevel)
|
logrus.SetLevel(logrus.FatalLevel)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package logging
|
package logging
|
||||||
|
|
||||||
type Config struct {
|
type PackageConfig struct {
|
||||||
LogLevel string `mapstructure:"LOG_LEVEL"`
|
LogLevel string `mapstructure:"LOG_LEVEL"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
package message
|
package message
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
Message string `json:"message" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
Responses uint
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NotFound Responses = iota
|
NotFound Responses = iota
|
||||||
CannotOpen
|
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"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
|
||||||
Router *chi.Mux
|
|
||||||
Hub *hub.Hub
|
|
||||||
Port int
|
|
||||||
AllowedHosts []string `mapstructure:"ALLOWED_HOSTS"`
|
|
||||||
Swagger bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var server = Server{}
|
var server = Server{}
|
||||||
|
|
||||||
func NewServer() {
|
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"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config = SystemConfig{}
|
var Config = PackageConfig{}
|
||||||
var Sys = System{}
|
var Sys = System{}
|
||||||
|
|
||||||
func NewSystemService() {
|
func NewSystemService() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
type SystemConfig struct {
|
type PackageConfig struct {
|
||||||
LiveSystem bool `mapstructure:"LIVE_SYSTEM"`
|
LiveSystem bool `mapstructure:"LIVE_SYSTEM"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ type CPU struct {
|
||||||
|
|
||||||
type Host struct {
|
type Host struct {
|
||||||
Architecture string `json:"architecture"`
|
Architecture string `json:"architecture"`
|
||||||
HostName string `json:"host_name"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ram struct {
|
type Ram struct {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package weather
|
package weather
|
||||||
|
|
||||||
type Config struct {
|
type PackageConfig struct {
|
||||||
Location Location
|
Location Location
|
||||||
OpenWeather OpenWeather `mapstructure:"OPEN_WEATHER"`
|
OpenWeather OpenWeather `mapstructure:"OPEN_WEATHER"`
|
||||||
Current OpenWeatherApiResponse
|
Current OpenWeatherApiResponse
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Conf = Config{}
|
var Conf = PackageConfig{}
|
||||||
var CurrentWeather = Weather{}
|
var CurrentWeather = Weather{}
|
||||||
|
|
||||||
func NewWeatherService() {
|
func NewWeatherService() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue