当前位置: 首页>>代码示例>>Golang>>正文


Golang routing-api.NewError函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/routing-api.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewError函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: requiredValidation

func requiredValidation(route db.Route) *routing_api.Error {
	err := validateRouteUrl(route.Route)
	if err != nil {
		return err
	}

	err = validateRouteServiceUrl(route.RouteServiceUrl)
	if err != nil {
		return err
	}

	if route.Port <= 0 {
		err := routing_api.NewError(routing_api.RouteInvalidError, "Each route request requires a port greater than 0")
		return &err
	}

	if route.Route == "" {
		err := routing_api.NewError(routing_api.RouteInvalidError, "Each route request requires a valid route")
		return &err
	}

	if route.IP == "" {
		err := routing_api.NewError(routing_api.RouteInvalidError, "Each route request requires an IP")
		return &err
	}

	return nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:28,代码来源:validator.go

示例2: validateTcpRouteMapping

func validateTcpRouteMapping(tcpRouteMapping db.TcpRouteMapping) *routing_api.Error {
	if tcpRouteMapping.TcpRoute.RouterGroupGuid == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a non empty router group guid. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.TcpRoute.ExternalPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a positive external port. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.HostIP == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a non empty backend ip. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.HostPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a positive backend port. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	return nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:27,代码来源:validator.go

示例3: handleUnauthorizedError

func handleUnauthorizedError(w http.ResponseWriter, err error, log lager.Logger) {
	log.Error("error", err)
	metrics.IncrementTokenError()
	retErr, _ := json.Marshal(routing_api.NewError(routing_api.UnauthorizedError, err.Error()))

	w.WriteHeader(http.StatusUnauthorized)
	w.Write(retErr)
}
开发者ID:shashankmjain,项目名称:gorouter,代码行数:8,代码来源:errors.go

示例4: handleProcessRequestError

func handleProcessRequestError(w http.ResponseWriter, procErr error, log lager.Logger) {
	log.Error("error", procErr)

	retErr, _ := json.Marshal(routing_api.NewError(routing_api.ProcessRequestError, "Cannot process request: "+procErr.Error()))

	w.WriteHeader(http.StatusBadRequest)
	w.Write(retErr)
}
开发者ID:shashankmjain,项目名称:gorouter,代码行数:8,代码来源:errors.go

示例5: handleDBCommunicationError

func handleDBCommunicationError(w http.ResponseWriter, err error, log lager.Logger) {
	log.Error("error", err)

	retErr, _ := json.Marshal(routing_api.NewError(routing_api.DBCommunicationError, err.Error()))

	w.WriteHeader(http.StatusInternalServerError)
	w.Write(retErr)
}
开发者ID:shashankmjain,项目名称:gorouter,代码行数:8,代码来源:errors.go

示例6: handleDBConflictError

func handleDBConflictError(w http.ResponseWriter, err error, log lager.Logger) {
	log.Error("error", err)

	retErr, _ := json.Marshal(routing_api.NewError(routing_api.DBConflictError, err.Error()))

	w.WriteHeader(http.StatusConflict)
	w.Write(retErr)
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:8,代码来源:errors.go

示例7: validateRouteServiceUrl

func validateRouteServiceUrl(routeService string) *routing_api.Error {
	if routeService == "" {
		return nil
	}

	if !strings.HasPrefix(routeService, "https://") {
		err := routing_api.NewError(routing_api.RouteServiceUrlInvalidError, "Route service url must use HTTPS.")
		return &err
	}

	err := validateUrl(routeService)
	if err != nil {
		err := routing_api.NewError(routing_api.RouteServiceUrlInvalidError, err.Error())
		return &err
	}

	return nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:18,代码来源:validator.go

示例8: validateRouteUrl

func validateRouteUrl(route string) *routing_api.Error {
	err := validateUrl(route)
	if err != nil {
		err := routing_api.NewError(routing_api.RouteInvalidError, err.Error())
		return &err
	}

	return nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:9,代码来源:validator.go

示例9: ValidateCreate

func (v Validator) ValidateCreate(routes []db.Route, maxTTL int) *routing_api.Error {
	for _, route := range routes {
		err := requiredValidation(route)
		if err != nil {
			return err
		}

		if route.TTL > maxTTL {
			err := routing_api.NewError(routing_api.RouteInvalidError, fmt.Sprintf("Max ttl is %d", maxTTL))
			return &err
		}

		if route.TTL <= 0 {
			err := routing_api.NewError(routing_api.RouteInvalidError, "Request requires a ttl greater than 0")
			return &err
		}
	}
	return nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:19,代码来源:validator.go

示例10: ValidateCreateTcpRouteMapping

func (v Validator) ValidateCreateTcpRouteMapping(tcpRouteMappings []db.TcpRouteMapping) *routing_api.Error {
	for _, tcpRouteMapping := range tcpRouteMappings {
		err := validateTcpRouteMapping(tcpRouteMapping)
		if err != nil {
			return err
		}
		if tcpRouteMapping.TcpRoute.RouterGroupGuid != helpers.DefaultRouterGroupGuid {
			err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
				"router_group_guid: "+tcpRouteMapping.TcpRoute.RouterGroupGuid+" not found")
			return &err
		}
	}
	return nil
}
开发者ID:idouba,项目名称:gorouter,代码行数:14,代码来源:validator.go

示例11: validateTcpRouteMapping

func validateTcpRouteMapping(tcpRouteMappings db.TcpRouteMapping) *routing_api.Error {

	if tcpRouteMappings.TcpRoute.RouterGroupGuid == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError, "Each tcp mapping requires a valid router group guid")
		return &err
	}

	if tcpRouteMappings.TcpRoute.ExternalPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError, "Each tcp mapping requires a positive external port")
		return &err
	}

	if tcpRouteMappings.HostIP == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError, "Each tcp mapping requires a non empty host ip")
		return &err
	}

	if tcpRouteMappings.HostPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError, "Each tcp mapping requires a positive host port")
		return &err
	}

	return nil
}
开发者ID:krumts,项目名称:gorouter,代码行数:24,代码来源:validator.go

示例12: ValidateCreateTcpRouteMapping

func (v Validator) ValidateCreateTcpRouteMapping(tcpRouteMappings []models.TcpRouteMapping, routerGroups models.RouterGroups, maxTTL uint16) *routing_api.Error {
	for _, tcpRouteMapping := range tcpRouteMappings {
		err := validateTcpRouteMapping(tcpRouteMapping, true, maxTTL)
		if err != nil {
			return err
		}

		validGuid := false
		for _, routerGroup := range routerGroups {
			if tcpRouteMapping.TcpRoute.RouterGroupGuid == routerGroup.Guid {
				validGuid = true
				break
			}
		}

		if !validGuid {
			err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
				"router_group_guid: "+tcpRouteMapping.TcpRoute.RouterGroupGuid+" not found")
			return &err
		}
	}
	return nil
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:23,代码来源:validator.go

示例13: validateTcpRouteMapping

func validateTcpRouteMapping(tcpRouteMapping models.TcpRouteMapping, checkTTL bool, maxTTL uint16) *routing_api.Error {
	if tcpRouteMapping.TcpRoute.RouterGroupGuid == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a non empty router group guid. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.TcpRoute.ExternalPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a positive external port. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.HostIP == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a non empty backend ip. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.HostPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a positive backend port. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if checkTTL && tcpRouteMapping.TTL > maxTTL {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires TTL to be less than or equal to "+strconv.Itoa(int(maxTTL))+". RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if checkTTL && tcpRouteMapping.TTL <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp route mapping requires a ttl greater than 0")
		return &err
	}

	return nil
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:39,代码来源:validator.go

示例14:

					request = handlers.NewTestRequest(`[{"route":{"router_group_guid": "tcp-default", "external_port": 5200}, "host_ip": "10.1.1.12", "host_port": 65537}]`)

					tcpRouteMappingsHandler.Upsert(responseRecorder, request)

					Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
					Expect(responseRecorder.Body.String()).To(ContainSubstring("cannot unmarshal number 65537 into Go value of type uint16"))
					Expect(database.SaveRouteCallCount()).To(Equal(0))
					Expect(logger.Logs()[0].Message).To(ContainSubstring("error"))

				})

			})

			Context("when validator returns error", func() {
				BeforeEach(func() {
					err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError, "Each tcp mapping requires a valid router group guid")
					validator.ValidateTcpRouteMappingReturns(&err)
				})

				It("returns error", func() {
					request = handlers.NewTestRequest(`[{"route":{"router_group_guid": "", "external_port": 52000}, "host_ip": "10.1.1.12", "host_port": 60000}]`)
					tcpRouteMappingsHandler.Upsert(responseRecorder, request)
					Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
					Expect(responseRecorder.Body.String()).To(ContainSubstring("Each tcp mapping requires a valid router group guid"))
					Expect(database.SaveRouteCallCount()).To(Equal(0))
					Expect(logger.Logs()[1].Message).To(ContainSubstring("error"))
				})
			})

			Context("when the UAA token is not valid", func() {
				BeforeEach(func() {
开发者ID:krumts,项目名称:gorouter,代码行数:31,代码来源:tcp_route_mappings_handler_test.go


注:本文中的github.com/cloudfoundry-incubator/routing-api.NewError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。