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


Golang UserRecord.Error方法代码示例

本文整理汇总了Golang中github.com/mdlayher/goat/goat/data.UserRecord.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang UserRecord.Error方法的具体用法?Golang UserRecord.Error怎么用?Golang UserRecord.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/mdlayher/goat/goat/data.UserRecord的用法示例。


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

示例1: parseHTTP

// Parse incoming HTTP connections before making tracker calls
func parseHTTP(w http.ResponseWriter, r *http.Request) {
	// Create a tracker to handle this client
	httpTracker := tracker.HTTPTracker{}

	// Add header to identify goat
	w.Header().Add("Server", fmt.Sprintf("%s/%s", App, Version))

	// Store current URL path
	url := r.URL.Path

	// Split URL into segments
	urlArr := strings.Split(url, "/")

	// If configured, Detect if client is making an API call
	url = urlArr[1]
	if url == "api" {
		// Output JSON
		w.Header().Add("Content-Type", "application/json")

		// Check if API enabled
		if !common.Static.Config.API {
			http.Error(w, api.ErrorResponse("API is currently disabled"), 503)
			return
		}

		// Count incoming connections
		atomic.AddInt64(&common.Static.API.Minute, 1)
		atomic.AddInt64(&common.Static.API.HalfHour, 1)
		atomic.AddInt64(&common.Static.API.Hour, 1)
		atomic.AddInt64(&common.Static.API.Total, 1)

		// API authentication
		var apiAuth api.APIAuthenticator

		// For login, make use of HTTP Basic + bcrypt authenticator
		if r.Method == "POST" && urlArr[2] == "login" {
			apiAuth = new(api.BasicAuthenticator)
		} else {
			// For all other calls, use HMAC authenticator
			apiAuth = new(api.HMACAuthenticator)
		}

		// Attempt authentication
		clientErr, serverErr := apiAuth.Auth(r)

		// Check for client error
		if clientErr != nil {
			// Check for additional server error
			if serverErr != nil {
				log.Println(serverErr.Error())
			}

			http.Error(w, api.ErrorResponse("Authentication failed: "+clientErr.Error()), 401)
			return
		}

		// Check for server error
		if serverErr != nil {
			log.Println(serverErr.Error())
			http.Error(w, api.ErrorResponse("API failure"), 500)
			return
		}

		// Attempt to retrieve session details from authenticator
		session, err := apiAuth.Session()
		if err != nil {
			log.Println(err.Error())
			http.Error(w, api.ErrorResponse("API session failure"), 500)
			return
		}

		// Handle API calls, output JSON
		api.Router(w, r, session)
		return
	}

	// Count incoming connections
	atomic.AddInt64(&common.Static.HTTP.Minute, 1)
	atomic.AddInt64(&common.Static.HTTP.HalfHour, 1)
	atomic.AddInt64(&common.Static.HTTP.Hour, 1)
	atomic.AddInt64(&common.Static.HTTP.Total, 1)

	// Check for maintenance mode
	if common.Static.Maintenance {
		// Return tracker error with maintenance message
		if _, err := w.Write(httpTracker.Error("Maintenance: " + common.Static.StatusMessage)); err != nil {
			log.Println(err.Error())
		}

		return
	}

	// Detect if passkey present in URL
	var passkey string
	if len(urlArr) == 3 {
		passkey = urlArr[1]
		url = urlArr[2]
	}

//.........这里部分代码省略.........
开发者ID:gernest,项目名称:goat,代码行数:101,代码来源:httpRouter.go


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