예제 #1
0
파일: model.go 프로젝트: eatfirst/vulcand
func NewListener(id, protocol, network, address, scope string, settings *HTTPSListenerSettings) (*Listener, error) {
	protocol = strings.ToLower(protocol)
	if protocol != HTTP && protocol != HTTPS {
		return nil, fmt.Errorf("unsupported protocol '%s', supported protocols are http and https", protocol)
	}

	if scope != "" {
		if !route.IsValid(scope) {
			return nil, fmt.Errorf("Scope should be a valid route expression")
		}
	}

	a, err := NewAddress(network, address)
	if err != nil {
		return nil, err
	}

	return &Listener{
		Scope:    scope,
		Id:       id,
		Address:  *a,
		Protocol: protocol,
		Settings: settings,
	}, nil
}
예제 #2
0
파일: model.go 프로젝트: eatfirst/vulcand
func NewHTTPFrontend(id, backendId string, routeExpr string, settings HTTPFrontendSettings) (*Frontend, error) {
	if len(id) == 0 || len(backendId) == 0 {
		return nil, fmt.Errorf("supply valid  route, id, and backendId")
	}

	// Make sure location path is a valid route expression
	if !route.IsValid(routeExpr) {
		return nil, fmt.Errorf("route should be a valid route expression: %s", routeExpr)
	}

	if settings.FailoverPredicate != "" && !stream.IsValidExpression(settings.FailoverPredicate) {
		return nil, fmt.Errorf("invalid failover predicate: %s", settings.FailoverPredicate)
	}

	return &Frontend{
		Id:        id,
		BackendId: backendId,
		Route:     routeExpr,
		Type:      HTTP,
		Settings:  settings,
	}, nil
}