本文整理汇总了Golang中github.com/sendgrid/ln.Err函数的典型用法代码示例。如果您正苦于以下问题:Golang Err函数的具体用法?Golang Err怎么用?Golang Err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Err函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AddTemplate
// AddTemplate inserts a template record
func (adaptor *Adaptor) AddTemplate(scopeTemplate ScopeTemplate) error {
postURL := fmt.Sprintf("http://%s:%d/v1/permissions/scopesettemplates", adaptor.Host, adaptor.Port)
b, err := json.Marshal(scopeTemplate)
if err != nil {
ln.Err("authzd adaptor error", ln.Map{"error": err.Error(), "method": "AddTemplate", "scopeTemplate": scopeTemplate})
return fmt.Errorf("error marshalling scope template - %s", err)
}
data := bytes.NewBuffer(b)
resp, err := http.Post(postURL, "application/json", data)
if err != nil {
ln.Err("authzd adaptor error", ln.Map{"error": err.Error(), "method": "AddTemplate", "scopeTemplate": scopeTemplate})
return fmt.Errorf("error posting data '%s' to url %s", b, postURL)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusConflict {
body, _ := ioutil.ReadAll(resp.Body)
ln.Err("authzd adaptor error", ln.Map{"error": fmt.Sprintf("error posting data '%s' to url %s - got status %d, want 200 or 409; %s", b, postURL, resp.StatusCode, body), "method": "AddTemplate", "scopeTemplate": scopeTemplate})
return fmt.Errorf("error posting data '%s' to url %s - got status %d, want 200 or 409; %s", b, postURL, resp.StatusCode, body)
}
return nil
}
示例2: ChangePackage
func (b *Adaptor) ChangePackage(userID int, packageID int, immediateChange bool, addOn ...string) *adaptor.AdaptorError {
var effectiveDate time.Time
if immediateChange {
effectiveDate = time.Now()
} else {
effectiveDate = FindDowngradeDate(time.Now())
}
putBody := BossUpdatePackageParams{
PackageID: packageID,
AddOn: addOn,
EffectiveDate: effectiveDate.Format("2006-01-02"),
}
updatePackageURL := fmt.Sprintf("%s/billing_provider_api/v1/users/%d/user_package", b.bossURL, userID)
authToken := fmt.Sprintf("token=%s", b.authToken)
client := &http.Client{}
data, err := json.Marshal(putBody)
if err != nil {
ln.Err("something went wrong marshalling change package put body", ln.Map{"error": err.Error(), "user_id": userID})
return adaptor.NewError("could not marshal put body")
}
req, err := http.NewRequest("PUT", updatePackageURL, bytes.NewReader(data))
if err != nil {
ln.Err("something went wrong creating http request for boss update package", ln.Map{"error": err.Error()})
return adaptor.NewError("could not create put request")
}
req.Header.Set("Authorization", authToken)
req.Header.Set("Content-Type", "application/json")
curl := fmt.Sprintf("curl -v -X PUT %s -d '%s' --header 'Authorization: <auth token>' --header 'Content-Type: application/json'", updatePackageURL, string(data))
resp, err := client.Do(req)
if err != nil {
ln.Err(fmt.Sprintf("something went wrong executing http request to boss update user package endpoint, %s", curl), ln.Map{"error": err.Error()})
return adaptor.NewError("error when calling PUT")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
ln.Err(fmt.Sprintf("Error reading response body, %s", curl), ln.Map{"error": err.Error(), "boss_status_code": resp.StatusCode})
return adaptor.NewError("could not read response body")
}
ln.Err(fmt.Sprintf("Error posting to subscriptions, %s", curl), ln.Map{"status_code": resp.StatusCode, "response_body": string(b), "user_id": userID, "url": updatePackageURL})
return adaptor.NewError("error when calling internal service")
}
return nil
}
示例3: CreateUserScopeSet
// CreateUserScopeSet creates a scope set for a given user using a scope set template, returns scope_set_id
func (adaptor *Adaptor) CreateUserScopeSet(userID int, template string) (string, error) {
postURL := fmt.Sprintf("http://%s:%d/v1/permissions/users/%d/scopeset", adaptor.Host, adaptor.Port, userID)
data := bytes.NewBufferString(fmt.Sprintf(`{"new_template":"%s"}`, template))
dataBackup := bytes.NewBufferString(fmt.Sprintf(`{"new_template":"%s"}`, template))
resp, err := http.Post(postURL, "application/json", data)
if err != nil {
ln.Err("authzd adaptor error", ln.Map{"method": "SetUserTemplate", "user_id": userID, "template": template})
return "", fmt.Errorf("error posting url %s - data %s - err %s", postURL, data, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
body, _ := ioutil.ReadAll(resp.Body)
ln.Err("authzd adaptor error", ln.Map{"method": "SetUserTemplate", "reason": fmt.Sprintf("error posting url %s - data %s - got status %d, want %d; body %s", postURL, dataBackup, resp.StatusCode, http.StatusCreated, body)})
return "", fmt.Errorf("error posting url %s - data %s - got status %d, want %d; body %s", postURL, dataBackup, resp.StatusCode, http.StatusCreated, body)
}
var result scopeSetID
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return "", fmt.Errorf("error getting scope set id on create user scope set call")
}
return result.ID, nil
}
示例4: AssignExternalIP
func (a *Adaptor) AssignExternalIP(userID int, ip string) *adaptor.AdaptorError {
var eIP []ExternalIP
err := a.apidClient.DoFunction("getExternalIp", url.Values{"ip": []string{ip}, "exclude_whitelabels": []string{strconv.Itoa(0)}}, &eIP)
if err != nil {
ln.Err("error when getting external ips of user", ln.Map{"error": err.Error(), "user_id": userID, "ip": ip})
return adaptor.NewError("error when getting external ips of user")
}
params := url.Values{
"ip": []string{ip},
"reseller_id": []string{strconv.Itoa(userID)},
"server_name_id": []string{strconv.Itoa(eIP[0].ServerID)},
"in_sender_score": []string{strconv.Itoa(eIP[0].InSenderScore)},
}
var result int
err = a.apidClient.DoFunction("editExternalIp", params, &result)
if err != nil {
ln.Err("error when editing external ip of user", ln.Map{"error": err.Error(), "user_id": userID, "ip": ip})
return adaptor.NewError("error when editing external ip of user")
}
return nil
}
示例5: Check
func (b *Adaptor) Check() error {
url := fmt.Sprintf("%s/healthcheck", b.bossURL)
resp, err := http.Get(url)
if err != nil {
ln.Err(
UnreachableErrorMessage,
ln.Map{"error": UnreachableError,
"bossURL": b.bossURL,
},
)
return UnreachableError
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
ln.Err(
UnreachableErrorMessage,
ln.Map{
"bossURL": b.bossURL,
},
)
return UnreachableError
}
return nil
}
示例6: GetCredentialScopeSetID
// GetCredentialScopeSetID returns the credentials's scope set id (uuid)
func (adaptor *Adaptor) GetCredentialScopeSetID(credentialID int) (string, error) {
getURL := fmt.Sprintf("http://%s:%d/v1/permissions/credentials/%d/scopeset", adaptor.Host, adaptor.Port, credentialID)
resp, err := http.Get(getURL)
if err != nil {
ln.Err("authzd adaptor error", ln.Map{"error": err.Error(), "credential_id": credentialID})
return "", fmt.Errorf("error getting url %s - %s", getURL, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := ioutil.ReadAll(resp.Body)
return "", fmt.Errorf("error getting url %s - got status %d, want %d; %s", getURL, resp.StatusCode, http.StatusOK, body)
}
data := scopeSetID{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
ln.Err("authzd adaptor error", ln.Map{"error": err.Error(), "method": "GetCredentialScopeSetID", "credential_id": credentialID})
return "", fmt.Errorf("error decoding body from url %s, %s", getURL, err)
}
return data.ID, nil
}
示例7: EditUserProfile
func (a *Adaptor) EditUserProfile(userProfile *client.UserProfile) (bool, *adaptor.AdaptorError) {
var editSuccess int
params, queryErr := query.Values(userProfile)
if queryErr != nil {
ln.Err("error query user profile", ln.Map{"err": queryErr.Error()})
return false, adaptor.NewError("error query user profile")
}
err := a.apidClient.DoFunction("editUserProfile", params, &editSuccess)
if err != nil {
ln.Err("error updating user profile", ln.Map{"err": err.Error(), "user_profile": userProfile})
return false, adaptor.NewError("error updating user profile")
}
if editSuccess == 0 {
// check if the user exists
user, adaptorError := a.GetUserProfile(userProfile.UserID)
if adaptorError != nil {
ln.Err("error when getting user profile", ln.Map{"err": adaptorError.Error(), "user_id": userProfile.UserID})
return false, adaptor.NewError("error when getting user profile")
}
if user == nil {
return false, adaptor.NewErrorWithStatus("user profile not found", http.StatusNotFound)
}
// no fields were changed
return true, nil
}
return true, nil
}
示例8: refresh
func (u *urlCache) refresh() error {
req, _ := http.NewRequest("GET", u.billingProviderURL, nil)
req.Header.Set("Authorization", fmt.Sprintf("token=%s", u.authToken))
req.Header.Set("Content-Type", "application/json")
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
ln.Err("could not refresh billing provider urls cache", ln.Map{"error": err.Error()})
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
ln.Err("error when getting billing provider urls", ln.Map{"code": resp.StatusCode})
return errors.New("could not get billing provider urls")
}
var urls BillingProviderURLResponse
err = json.NewDecoder(resp.Body).Decode(&urls)
u.cache.Set(URLCacheKeyAccountUrl, urls.AccountURL)
u.cache.Set(URLCacheKeyPackagePreviewURL, urls.PackagePreviewURL)
u.cache.Set(URLCacheKeyAccountSubscriptionURL, urls.AccountSubscriptionURL)
u.cache.Set(URLCacheKeyAccountPaymentMethodURL, urls.AccountPaymentMethodURL)
u.cache.Set(URLCacheKeyAccountCollectURL, urls.AccountCollectURL)
return nil
}
示例9: insertNewCompetitor
func (a *Adaptor) insertNewCompetitor(userID int, otherProvider string) (int, *adaptor.AdaptorError) {
addParams := url.Values{
"user_id": []string{strconv.Itoa(userID)},
"competitor": []string{otherProvider},
}
columns := NewCrudColumns()
columns.AddColumns(addParams)
// add new user package
var ok string
err := a.apidClient.DoFunction("add", url.Values{
"tableName": []string{"competitors"},
"values": []string{columns.String()},
}, &ok)
if err != nil {
ln.Err("unable to add to competitor table", ln.Map{"err": err.Error()})
return 0, adaptor.NewError("internal data storage error")
}
if ok != "success" {
ln.Err("error adding to competitor table", ln.Map{"err": fmt.Sprintf("%s - %s", ok, err.Error())})
return 0, adaptor.NewError("internal data storage error")
}
return a.getInvalidCompetitorID(userID, otherProvider)
}
示例10: ChangePassword
func (g *Adaptor) ChangePassword(userID int, password string) error {
changePasswordURL := fmt.Sprintf("http://%s:%d/password", g.GandalfHost, g.GandalfPort)
changePWReq := &ChangePasswordRequest{
UserID: userID,
Password: password,
}
data, err := json.Marshal(changePWReq)
if err != nil {
ln.Err("could not marshal changePassword request parameters", ln.Map{"error": err.Error(), "user_id": userID})
return errors.New(ErrorChangePassword)
}
req, err := http.NewRequest("PUT", changePasswordURL, bytes.NewBuffer(data))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
ln.Err("error posting to gandalf password endpoint", ln.Map{"error": err.Error(), "user_id": userID})
return errors.New(ErrorChangePassword)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
ln.Err("error calling password endpoint in gandalf", ln.Map{"status": resp.StatusCode, "user_id": userID})
return errors.New(ErrorChangePassword)
}
return nil
}
示例11: PackageIDFromUUID
func (a *Adaptor) PackageIDFromUUID(packageUUID string) (int, *adaptor.AdaptorError) {
params := url.Values{
"tableName": []string{"package"},
"where": []string{fmt.Sprintf(`{"uuid":"%s"}`, packageUUID)},
}
var packages []struct {
ID int `json:"id"`
}
err := a.apidClient.DoFunction("get", params, &packages)
if err != nil {
ln.Err("error calling get for user package", ln.Map{"error": err.Error(), "uuid": packageUUID})
formattedErr := adaptor.NewError("unable to process request")
return -1, formattedErr
}
if len(packages) != 1 {
ln.Err("did not get one result back from get call for user package", ln.Map{"uuid": packageUUID})
formattedErr := adaptor.NewError(ErrorNoPackagesFound)
return -1, formattedErr
}
return packages[0].ID, nil
}
示例12: Check
func (g *Adaptor) Check() error {
resp, err := http.Get(fmt.Sprintf("http://%s:%d/healthcheck", g.GandalfHost, g.GandalfHealthcheckPort))
if err != nil {
ln.Err(
ErrorUnreachable,
ln.Map{
"error": err.Error(),
"gandalf_host": g.GandalfHost,
"gandalf_healthcheck_port": g.GandalfHealthcheckPort,
},
)
return unreachable
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
ln.Err(
ErrorUnreachable,
ln.Map{
"gandalf_host": g.GandalfHost,
"gandalf_healthcheck_port": g.GandalfHealthcheckPort,
},
)
return unreachable
}
return nil
}
示例13: InsertDeactivationReason
func (a *Adaptor) InsertDeactivationReason(userID int, reason string, moving bool, inHouse bool, otherProvider string, comment string) *adaptor.AdaptorError {
reasonID, adaptorErr := a.getReasonID(reason)
if adaptorErr != nil {
return adaptorErr
}
if inHouse {
otherProvider = "in house"
}
competitorID, adaptorErr := a.getValidCompetitorID(otherProvider)
if adaptorErr != nil {
ln.Err("unable to get competitor id - "+otherProvider, ln.Map{"err": adaptorErr})
return adaptorErr
}
if competitorID == 0 {
competitorID, adaptorErr = a.insertNewCompetitor(userID, otherProvider)
if adaptorErr != nil {
ln.Err("unable to set new competitor id - "+otherProvider, ln.Map{"err": adaptorErr})
return adaptorErr
}
}
params := url.Values{
"user_id": []string{strconv.Itoa(userID)},
"moving": []string{strconv.Itoa(boolToInt(moving))},
"event_type": []string{"Cancellation"},
"new_provider": []string{strconv.Itoa(competitorID)},
"notes": []string{comment},
"reason": []string{strconv.Itoa(reasonID)},
}
columns := NewCrudColumns()
columns.AddColumns(params)
var ok string
err := a.apidClient.DoFunction("add", url.Values{
"tableName": []string{"user_churn"},
"values": []string{columns.String()},
}, &ok)
if err != nil {
ln.Info("unable to call apid add on user_churn", ln.Map{"err": err.Error(), "user_id": userID})
return adaptor.NewError("internal data storage error")
}
if ok != "success" {
ln.Info("unexpected response from apid add on user_churn", ln.Map{"err": fmt.Sprintf("got '%s', want 'success'", ok), "user_id": userID})
}
return nil
}
示例14: SetUserPackage
func (a *Adaptor) SetUserPackage(userID int, packageID int) *adaptor.AdaptorError {
var delSuccess int
var userPackage string
packageIDString := strconv.Itoa(packageID)
pkg, adaptorErr := a.GetPackage(packageID)
if adaptorErr != nil {
return adaptorErr
}
// delete the user's old package
err := a.apidClient.DoFunction("delete", url.Values{
"tableName": []string{"user_package"},
"where": []string{`{"user_id" : "` + strconv.Itoa(userID) + `"}`},
}, &delSuccess)
if err != nil {
ln.Err("Something went wrong trying to delete the user's current package", ln.Map{"error": err.Error(), "user_id": userID})
return adaptor.NewError("Something went wrong trying to delete the user's current package")
}
params := url.Values{
"user_id": []string{strconv.Itoa(userID)},
"status": []string{strconv.Itoa(UserStatusSendGridPaid)},
"package_id": []string{packageIDString},
"package_group_id": []string{strconv.Itoa(pkg.GroupID)},
"package_status": []string{strconv.Itoa(PackageStatusActive)},
"start_date": []string{time.Now().Format("2006-01-02")},
"end_date": []string{now.New(time.Now().AddDate(0, 1, 0)).BeginningOfMonth().Format("2006-01-02")},
"subusers_limit": []string{strconv.Itoa(DefaultSubuserLimit)},
"updated_at": []string{time.Now().String()},
}
columns := NewCrudColumns()
columns.AddColumns(params)
// add new user package
err = a.apidClient.DoFunction("add", url.Values{
"tableName": []string{"user_package"},
"values": []string{columns.String()},
}, &userPackage)
if err != nil {
ln.Err("Something went wrong trying to add a package for the user", ln.Map{"error": err.Error(), "user_id": userID, "package_id": packageID})
return adaptor.NewError("Something went wrong trying to add the user's package")
}
return nil
}
示例15: GetAuthorizationToken
func (g *Adaptor) GetAuthorizationToken(userid int) (string, error) {
// Get existing token if it exists
getURL := fmt.Sprintf("http://%s:%d/tokens/%d", g.GandalfHost, g.GandalfPort, userid)
resp, err := http.Get(getURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
var tokens []gandalfToken
err = json.NewDecoder(resp.Body).Decode(&tokens)
if err != nil {
ln.Err("error when decoding tokens", ln.Map{"method": "GetAuthorizationToken", "user_id": userid, "error": err.Error()})
}
if len(tokens) > 0 {
return tokens[0].Token, nil
}
generateURL := fmt.Sprintf("http://%s:%d/generate/%d", g.GandalfHost, g.GandalfPort, userid)
client := http.Client{}
req, err := http.NewRequest("GET", generateURL, nil)
req.Header.Set("Content-Type", "application/json")
if err != nil {
ln.Err("error when create request for the generate token url", ln.Map{"method": "GetAuthorizationToken", "user_id": userid, "error": err.Error()})
return "", getTokenError
}
resp, err = client.Do(req)
if err != nil {
ln.Err("error when calling generate token", ln.Map{"method": "GetAuthorizationToken", "user_id": userid, "error": err.Error()})
return "", getTokenError
}
defer resp.Body.Close()
var tokenResponse TokenResponse
err = json.NewDecoder(resp.Body).Decode(&tokenResponse)
if err != nil {
ln.Err("error when decoding gnereated token response", ln.Map{"method": "GetAuthorizationToken", "user_id": userid, "error": err.Error()})
return "", getTokenError
}
return tokenResponse.Token, nil
}