Skip to content

Commit

Permalink
修改config
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoK29 committed May 13, 2022
1 parent 98c4141 commit 35d4827
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 128 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ gofound
/*/*.bin
/dist/
/cache
/tests/index
/tests/index
/data
29 changes: 29 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 系统设置
system:
# 服务监听地址
addr: 127.0.0.1:5678
# 是否开启debug模式
debug: false
# 是否开启gzip压缩
enableGzip: false

# 是否开启认证
auth:
enable: false
# 认证用户名
username: admin
# 认证密码
password: 123456

# 搜索引擎部分
engine:
# 数据存放路径
dataDir: ./data
# 词库路径
dictionaryDir: ./searcher/words/data/dictionary.txt
# 文件分块
shard: 5
# 索引队列最大值
queueMax: 1000
# GC时间间隔
gcInterval: 10
29 changes: 0 additions & 29 deletions config.yml

This file was deleted.

8 changes: 8 additions & 0 deletions config/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

// Auth 权限设置
type Auth struct {
Enable bool `mapstructure:"enable" json:"enable" yaml:"enable"` // 是否开启
Username string `mapstructure:"username" json:"username" yaml:"username"` // 用户名
Password string `mapstructure:"password" json:"password" yaml:"password"` // 用户密码
}
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

// Server 服务器设置
type Server struct {
System *System `mapstructure:"system" json:"system" yaml:"system"` // 系统设置
Auth *Auth `mapstructure:"auth" json:"auth" yaml:"auth"` // 认证设置
Engine *Engine `mapstructure:"engine" json:"engine" yaml:"engine"` // 搜索引擎设置
}
10 changes: 10 additions & 0 deletions config/engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package config

// Engine 搜索引擎
type Engine struct {
DataDir string `mapstructure:"dataDir" json:"dataDir" yaml:"dataDir"` // 数据存放路径
DictionaryDir string `mapstructure:"dictionaryDir" json:"dictionaryDir" yaml:"dictionaryDir"` // 词库路径
Shard int `mapstructure:"shard" json:"shard" yaml:"shard"` // 文件分块
QueueMax int `mapstructure:"queue_max" json:"queueMax" yaml:"queueMax"` // 索引队列最大值
GcInterval int `mapstructure:"gcInterval" json:"gcInterval" yaml:"gcInterval"` // GC时间间隔
}
8 changes: 8 additions & 0 deletions config/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

// System 系统设置
type System struct {
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"` // 服务监听地址
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"` // 是否开启debug模式
EnableGzip bool `mapstructure:"enableGzip" json:"enableGzip" yaml:"enableGzip"` // 是否开启gzip压缩
}
23 changes: 23 additions & 0 deletions core/viper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package core

import (
"gofound/global"

"github.com/spf13/viper"
)

// Viper 解析器
func Viper(config string) *viper.Viper {
v := viper.New()
v.SetConfigFile(config)
err := v.ReadInConfig()
if err != nil {
panic(err)
}

if err := v.Unmarshal(&global.CONFIG); err != nil {
panic(err)
}

return v
}
12 changes: 12 additions & 0 deletions global/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package global

import (
"gofound/config"

"github.com/spf13/viper"
)

var (
VP *viper.Viper // 解析器
CONFIG *config.Server // 服务器设置
)
34 changes: 25 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,50 @@ go 1.18

require (
github.com/emirpasic/gods v1.12.0
github.com/gin-contrib/gzip v0.0.5
github.com/gin-gonic/gin v1.7.7
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46
github.com/shirou/gopsutil/v3 v3.22.4
github.com/spf13/viper v1.11.0
github.com/syndtr/goleveldb v1.0.0
github.com/wangbin/jiebago v0.3.2
)

require (
github.com/gin-contrib/gzip v0.0.5 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit 35d4827

Please sign in to comment.