本文整理匯總了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]
}
//.........這裏部分代碼省略.........