mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
feat: Add migration
Signed-off-by: zu1k <i@zu1k.com>
This commit is contained in:
parent
2f1d16408c
commit
8e280304bb
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/ip2location/ip2location-go/v9 v9.4.0
|
||||
github.com/ipipdotnet/ipdb-go v1.3.1
|
||||
github.com/lionsoul2014/ip2region v2.2.0-release+incompatible
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220704023600-9376c56688c8
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220705082050-0f0c0cb4a5a6
|
||||
github.com/oschwald/geoip2-golang v1.7.0
|
||||
github.com/saracen/go7z v0.0.0-20191010121135-9c09b6bd7fda
|
||||
github.com/spf13/cobra v1.5.0
|
||||
|
2
go.sum
2
go.sum
@ -148,6 +148,8 @@ github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777ab
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777abd9d/go.mod h1:bChUKvbKVC3zL/lLLIcu6alhQaL8uWD/DA+jRdyggdI=
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220704023600-9376c56688c8 h1:aHOC8Mcbd3TiCb+L9cSbU/NdZinWuaKSoL4qD4I3MQo=
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220704023600-9376c56688c8/go.mod h1:bChUKvbKVC3zL/lLLIcu6alhQaL8uWD/DA+jRdyggdI=
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220705082050-0f0c0cb4a5a6 h1:4lJlR7mskbInnkGSixv0l7Ew/SD+xQUqWKu0KwvkpiI=
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220705082050-0f0c0cb4a5a6/go.mod h1:bChUKvbKVC3zL/lLLIcu6alhQaL8uWD/DA+jRdyggdI=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
|
54
internal/migration/v4.go
Normal file
54
internal/migration/v4.go
Normal file
@ -0,0 +1,54 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/zu1k/nali/internal/constant"
|
||||
"github.com/zu1k/nali/internal/db"
|
||||
"github.com/zu1k/nali/pkg/cdn"
|
||||
"github.com/zu1k/nali/pkg/ip2region"
|
||||
)
|
||||
|
||||
func init() {
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(constant.WorkDirPath)
|
||||
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
err = viper.SafeWriteConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
dbList := db.List{}
|
||||
err = viper.UnmarshalKey("databases", &dbList)
|
||||
if err != nil {
|
||||
log.Fatalln("Config invalid:", err)
|
||||
}
|
||||
|
||||
needOverwrite := false
|
||||
for _, adb := range dbList {
|
||||
if adb.Name == "ip2region" && adb.File != "ip2region.xdb" {
|
||||
needOverwrite = true
|
||||
adb.File = "ip2region.xdb"
|
||||
adb.DownloadUrls = ip2region.DownloadUrls
|
||||
}
|
||||
|
||||
if adb.Name == "cdn" && adb.Format != "cdn-yml" {
|
||||
needOverwrite = true
|
||||
adb.Format = "cdn-yml"
|
||||
adb.DownloadUrls = cdn.DownloadUrls
|
||||
}
|
||||
}
|
||||
|
||||
if needOverwrite {
|
||||
viper.Set("databases", dbList)
|
||||
err = viper.WriteConfig()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user