本文整理汇总了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]
}
//.........这里部分代码省略.........