From 67e5364f16b5bc4b5f04cf3146b97aa162040b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 4 Nov 2020 20:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0API=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=9B=B4=E6=96=B0IP=E5=BA=93=E3=80=81?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E7=9A=84=E5=88=86=E6=9E=90=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/global_config.go | 9 ++++++++- .../{ip_library.go => ip_library_types.go} | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) rename pkg/serverconfigs/{ip_library.go => ip_library_types.go} (71%) diff --git a/pkg/serverconfigs/global_config.go b/pkg/serverconfigs/global_config.go index ff42dda..3470cc4 100644 --- a/pkg/serverconfigs/global_config.go +++ b/pkg/serverconfigs/global_config.go @@ -2,9 +2,11 @@ package serverconfigs // 服务相关的全局设置 type GlobalConfig struct { + // HTTP & HTTPS相关配置 HTTPAll struct { - MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` + MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名 } `yaml:"httpAll" json:"httpAll"` + HTTP struct{} `yaml:"http" json:"http"` HTTPS struct{} `yaml:"https" json:"https"` TCPAll struct{} `yaml:"tcpAll" json:"tcpAll"` @@ -12,6 +14,11 @@ type GlobalConfig struct { TLS struct{} `yaml:"tls" json:"tls"` Unix struct{} `yaml:"unix" json:"unix"` UDP struct{} `yaml:"udp" json:"udp"` + + // IP库相关配置 + IPLibrary struct { + Code string `yaml:"code" json:"code"` // 当前使用的IP库代号 + } `yaml:"ipLibrary" json:"ipLibrary"` } func (this *GlobalConfig) Init() error { diff --git a/pkg/serverconfigs/ip_library.go b/pkg/serverconfigs/ip_library_types.go similarity index 71% rename from pkg/serverconfigs/ip_library.go rename to pkg/serverconfigs/ip_library_types.go index 7389256..3846bd2 100644 --- a/pkg/serverconfigs/ip_library.go +++ b/pkg/serverconfigs/ip_library_types.go @@ -2,16 +2,24 @@ package serverconfigs import "github.com/iwind/TeaGo/maps" +type IPLibraryType = string + +const ( + IPLibraryTypeIP2Region IPLibraryType = "ip2region" +) + // 所有的IP库类型 var IPLibraryTypes = []maps.Map{ { "name": "ip2region", - "code": "ip2region", + "code": IPLibraryTypeIP2Region, "description": "一个开源的IP库:https://github.com/lionsoul2014/ip2region", "ext": ".db", }, } +var DefaultIPLibraryType = IPLibraryTypeIP2Region + // 根据类型查找IP库 func FindIPLibraryWithType(libraryType string) maps.Map { for _, t := range IPLibraryTypes {