Browse Source

revise bug

wangkang 9 months ago
parent
commit
ac39f6cc34
6 changed files with 5 additions and 79 deletions
  1. 0 4
      client/client.go
  2. 0 46
      config/config.go
  3. 0 5
      db/db.go
  4. 0 16
      logger/logger.go
  5. 2 5
      main.go
  6. 3 3
      router/router.go

+ 0 - 4
client/client.go

@@ -1,10 +1,6 @@
 package client
 
-import "web_test_cgi/config"
-
 var headers = map[string]string{
 	"Accept":       "application/json, text/plain, */*",
 	"Content-Type": "application/json",
 }
-
-var cfg = config.GetConfig()

+ 0 - 46
config/config.go

@@ -1,46 +0,0 @@
-package config
-
-import (
-	"github.com/spf13/viper"
-	"log"
-	"strings"
-)
-
-// Init read the base file
-func init() {
-	viper.AddConfigPath("./conf")
-	viper.AddConfigPath("../conf")
-	viper.SetConfigName("config")
-	viper.SetConfigType("yaml")
-	viper.AutomaticEnv()
-	replacer := strings.NewReplacer(".", "_")
-	viper.SetEnvKeyReplacer(replacer)
-	if err := viper.ReadInConfig(); err != nil {
-		log.Println("init config error ", err)
-		panic(err)
-	}
-}
-
-// Config 导出的配置类
-type Config struct {
-	Port     string
-	Mode     string
-	MongoURL string
-	DBName   string
-	DebugLog bool
-	TraceLog bool
-	LogFile  string
-}
-
-// GetConfig get config
-func GetConfig() *Config {
-	return &Config{
-		Port:     viper.GetString("port"),
-		Mode:     viper.GetString("mode"),
-		MongoURL: viper.GetString("mongo.url"),
-		DBName:   viper.GetString("mongo.db"),
-		DebugLog: viper.GetBool("debuglog"),
-		TraceLog: viper.GetBool("tracelog"),
-		LogFile:  viper.GetString("logfile"),
-	}
-}

+ 0 - 5
db/db.go

@@ -1,5 +0,0 @@
-package db
-
-import "web_test_cgi/config"
-
-var cfg = config.GetConfig()

+ 0 - 16
logger/logger.go

@@ -1,24 +1,8 @@
 package logger
 
-import "web_test_cgi/config"
-
 var l *Logger
 
 func init() {
-	cfg := config.GetConfig()
-
-	time := true
-	file := true
-	debug := cfg.DebugLog
-	trace := cfg.TraceLog
-	colors := true
-	pid := false
-
-	if cfg.LogFile == "" {
-		l = NewStdLogger(time, file, debug, trace, colors, pid)
-	} else {
-		l = NewFileLogger(cfg.LogFile, time, file, debug, trace, pid)
-	}
 }
 
 func GetLogger() *Logger {

+ 2 - 5
main.go

@@ -1,16 +1,13 @@
 package main
 
 import (
-	"web_test_cgi/config"
-	"web_test_cgi/logger"
-	"web_test_cgi/router"
 	"github.com/gin-gonic/gin"
 	"github.com/spf13/viper"
+	"web_test_cgi/logger"
+	"web_test_cgi/router"
 )
 
 func main() {
-
-	cfg := config.GetConfig()
 	gin.SetMode(cfg.Mode)
 	logger.GetLogger().Traceln(viper.AllSettings())
 

+ 3 - 3
router/router.go

@@ -1,10 +1,10 @@
 package router
 
 import (
-	"web_test_cgi/handler"
-	"web_test_cgi/router/middleware"
 	"github.com/gin-gonic/gin"
 	"net/http"
+	"web_test_cgi/handler"
+	"web_test_cgi/router/middleware"
 )
 
 // router.go 所有的路由放到这里
@@ -23,7 +23,7 @@ func Load(g *gin.Engine) *gin.Engine {
 	// 注意使用rest风格url
 	articleGroup := g.Group("/web_test_cgi")
 	{
-		articleGroup.GET("/user_info/:id", handler.GetArticles)
+		articleGroup.GET("/user_info", handler.GetArticles)
 		//articleGroup.POST("/article", handler.AddArticle)
 	}