소스 검색

Refactor files

Florian Hoss 2 년 전
부모
커밋
e55a4d02f2
11개의 변경된 파일30개의 추가작업 그리고 41개의 파일을 삭제
  1. 2 2
      logging/logging.go
  2. 1 1
      logging/type.go
  3. 0 8
      message/message.go
  4. 9 0
      message/types.go
  5. 0 17
      server/helpers.go
  6. 0 8
      server/server.go
  7. 14 0
      server/types.go
  8. 1 1
      system/system.go
  9. 1 2
      system/types.go
  10. 1 1
      weather/types.go
  11. 1 1
      weather/weather.go

+ 2 - 2
logging/logging.go

@@ -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 - 1
logging/type.go

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

+ 0 - 8
message/message.go

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

+ 9 - 0
message/types.go

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

+ 0 - 17
server/helpers.go

@@ -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)
-}

+ 0 - 8
server/server.go

@@ -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 - 0
server/types.go

@@ -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
+}

+ 1 - 1
system/system.go

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

+ 1 - 2
system/types.go

@@ -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 - 1
weather/types.go

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

+ 1 - 1
weather/weather.go

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