27 Star 109 Fork 25

MJ PC Lab/go-http-file-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
params.go 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
小小猫猫 提交于 2021-12-04 00:17 . feat: upgrade goVirtualHost v1.3.0
package goVirtualHost
import (
"errors"
"fmt"
)
var ConflictIPAddress = errors.New("conflict IP address")
var ConflictTLSMode = errors.New("cannot serve for both Plain and TLS mode")
var DuplicatedAddressHostname = errors.New("duplicated address and hostname")
func (params params) validateParam(param *param) (errs []error) {
for _, ownParam := range params {
if ownParam == param {
continue
}
if ownParam.port == param.port && ownParam.proto != unix && param.proto != unix {
ipConflict := false
if ownParam.proto == param.proto {
if ownParam.ip != param.ip && (ownParam.ip == "" || param.ip == "") {
ipConflict = true
}
} else {
if ownParam.proto == tcp46 || param.proto == tcp46 {
ipConflict = true
}
}
if ipConflict {
err := wrapError(ConflictIPAddress, fmt.Sprintf("conflict IP address: %+v, %+v", ownParam, param))
errs = append(errs, err)
}
}
if ownParam.proto == param.proto && ownParam.ip == param.ip && ownParam.port == param.port {
ownUseTLS := ownParam.cert != nil
useTLS := param.cert != nil
if ownUseTLS != useTLS {
err := wrapError(ConflictTLSMode, fmt.Sprintf("cannot serve for both Plain and TLS mode: %+v, %+v", ownParam, param))
errs = append(errs, err)
}
if (len(param.hostNames) == 0 && len(ownParam.hostNames) == 0) || (ownParam.hasHostNames(param.hostNames)) {
err := wrapError(DuplicatedAddressHostname, fmt.Sprintf("duplicated address and hostname: %+v, %+v", ownParam, param))
errs = append(errs, err)
}
}
}
return
}
func (params params) validate(inputs params) (errs []error) {
for _, p := range inputs {
es := p.validate()
if len(es) > 0 {
errs = append(errs, es...)
}
es = inputs.validateParam(p)
if len(es) > 0 {
errs = append(errs, es...)
}
es = params.validateParam(p)
if len(es) > 0 {
errs = append(errs, es...)
}
}
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mjpclab/go-http-file-server.git
git@gitee.com:mjpclab/go-http-file-server.git
mjpclab
go-http-file-server
go-http-file-server
v1.13.3-go1.9to1.15

搜索帮助