本文整理汇总了Golang中locale.UntranslatedError函数的典型用法代码示例。如果您正苦于以下问题:Golang UntranslatedError函数的具体用法?Golang UntranslatedError怎么用?Golang UntranslatedError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UntranslatedError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
func (server TwilioSMSCallbackServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
periwinkle.Logf("TwilioCallback")
fmt.Fprintf(w, "Hi there, I love %s!", req.URL.String())
body, err := ioutil.ReadAll(req.Body)
if err != nil {
periwinkle.LogErr(locale.UntranslatedError(err))
return
}
values, err := url.ParseQuery(string(body))
if err != nil {
periwinkle.LogErr(locale.UntranslatedError(err))
return
}
status := backend.TwilioSMSMessage{
MessageStatus: values.Get("MessageStatus"),
ErrorCode: values.Get("ErrorCode"),
MessageSID: values.Get("MessageSid"),
}
server.DB.Do(func(db *periwinkle.Tx) {
status.Save(db)
})
}
示例2: NewJSONPatch
// Diff two objects, and produce an RFC 6902 JSON Patch.
func NewJSONPatch(a interface{}, b interface{}) (jsonpatch.JSONPatch, locale.Error) {
// convert a to json
aBytes, uerr := json.Marshal(a)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
// convert b to json
bBytes, uerr := json.Marshal(b)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
// diff them
p, uerr := matt.CreatePatch(aBytes, bBytes)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
pBytes, uerr := json.Marshal(p)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
// return
var ret jsonpatch.JSONPatch
uerr = json.Unmarshal(pBytes, &ret)
return ret, locale.UntranslatedError(uerr)
}
示例3: DecoderFormData
// DecoderFormData maps multipart/form-data => json.Decoder # because fuckit
func DecoderFormData(r io.Reader, params map[string]string) (interface{}, locale.Error) {
boundary, ok := params["boundary"]
if !ok {
return nil, locale.UntranslatedError(http.ErrMissingBoundary)
}
reader := multipart.NewReader(r, boundary)
form, uerr := reader.ReadForm(0)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
entity := make(map[string]interface{}, len(form.Value)+len(form.File))
for k, v := range form.Value {
entity[k] = v
}
for k, v := range form.File {
if _, exists := entity[k]; exists {
values := entity[k].([]string)
list := make([]interface{}, len(values)+len(v))
i := uint(0)
for _, value := range values {
list[i] = value
i++
}
for _, value := range v {
list[i] = value
i++
}
entity[k] = list
} else {
entity[k] = v
}
}
return fuckitJSON(entity)
}
示例4: DeleteUnusedTwilioNumber
func DeleteUnusedTwilioNumber(db *periwinkle.Tx, num string) locale.Error {
var twilioNum TwilioNumber
if result := db.Where("number = ?", num).First(&twilioNum); result.Error != nil {
if result.RecordNotFound() {
periwinkle.Logf("The number is already deleted!!!")
return nil
}
dbError(result.Error)
return locale.UntranslatedError(result.Error)
}
var twilioPool TwilioPool
result := db.Where("number_id = ?", twilioNum.ID).First(&twilioPool)
if result.Error != nil {
if result.RecordNotFound() {
o := db.Where("number = ?", num).Delete(&TwilioNumber{})
if o.Error != nil {
dbError(o.Error)
return locale.UntranslatedError(o.Error)
}
periwinkle.Logf("The number is deleted")
return nil
}
dbError(result.Error)
return locale.UntranslatedError(result.Error)
}
periwinkle.Logf("The number is used for a twilio pool")
return nil
}
示例5: Write
func (l NetJSON) Write(w io.Writer, loc locale.Spec) locale.Error {
bytes, uerr := json.Marshal(l.Data)
if uerr != nil {
return locale.UntranslatedError(uerr)
}
_, uerr = w.Write(bytes)
return locale.UntranslatedError(uerr)
}
示例6: Write
func (e EncoderJSONStr) Write(w io.Writer, l locale.Spec) locale.Error {
bytes, err := json.Marshal(e.Data.L10NString(l))
if err != nil {
return locale.UntranslatedError(err)
}
_, err = w.Write(bytes)
return locale.UntranslatedError(err)
}
示例7: dbSeed
func (o Medium) dbSeed(db *periwinkle.Tx) locale.Error {
errs := errorList{}
errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"email"}).Error))
errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"sms"}).Error))
errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"mms"}).Error))
if len(errs) > 0 {
return errs
}
return nil
}
示例8: checkNumber
func checkNumber(config *periwinkle.Cfg, tx *periwinkle.Tx, number backend.TwilioNumber) {
url := "https://api.twilio.com/2010-04-01/Accounts/" + config.TwilioAccountID + "/Messages.json?To=" + number.Number
if lastPoll != timeZero {
url += "&DateSent>=" + strings.Split(lastPoll.UTC().String(), " ")[0]
}
req, _ := http.NewRequest("GET", url, nil)
req.SetBasicAuth(config.TwilioAccountID, config.TwilioAuthToken)
resp, uerr := (&http.Client{}).Do(req)
if uerr != nil {
periwinkle.LogErr(locale.UntranslatedError(uerr))
}
defer resp.Body.Close()
body, uerr := ioutil.ReadAll(resp.Body)
if uerr != nil {
periwinkle.LogErr(locale.UntranslatedError(uerr))
}
// converts JSON messages
var page twilio.Paging
json.Unmarshal([]byte(body), &page)
for _, message := range page.Messages {
timeSend, uerr := time.Parse(time.RFC1123Z, message.DateSent)
if uerr != nil {
periwinkle.LogErr(locale.UntranslatedError(uerr))
continue
}
if timeSend.Unix() < lastPoll.Unix() {
periwinkle.Logf("message %q older than our last poll; ignoring", message.Sid)
continue
}
user := backend.GetUserByAddress(tx, "sms", message.From)
if user == nil {
periwinkle.Logf("could not figure out which user has number %q", message.From)
continue
}
group := backend.GetGroupByUserAndTwilioNumber(tx, user.ID, message.To)
if group == nil {
periwinkle.Logf("could not figure out which group this is meant for: user: %q, number: %q", user.ID, message.To)
continue
}
periwinkle.Logf("received message for group %q", group.ID)
MessageBuilder{
Maildir: config.Mailstore,
Headers: map[string]string{
"To": group.ID + "@" + config.GroupDomain,
"From": backend.UserAddress{Medium: "sms", Address: message.From}.AsEmailAddress(),
"Subject": user.ID + ": " + message.Body,
},
Body: "",
}.Done()
}
}
示例9: Apply
// Apply the patch to an object; as if the object were
// marshalled/unmarshalled JSON.
func (patch JSONMergePatch) Apply(in interface{}, out interface{}) locale.Error {
inBytes, uerr := json.Marshal(in)
if uerr != nil {
return locale.UntranslatedError(uerr)
}
outBytes, uerr := evan.MergePatch(inBytes, patch)
if uerr != nil {
return locale.UntranslatedError(uerr)
}
return locale.UntranslatedError(json.Unmarshal(outBytes, out))
}
示例10: DecoderFormURLEncoded
// DecoderFormURLEncoded maps application/x-www-form-urlencoded => json.Decoder # because fuckit
func DecoderFormURLEncoded(r io.Reader, params map[string]string) (interface{}, locale.Error) {
bytes, uerr := ioutil.ReadAll(r)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
entity, uerr := url.ParseQuery(string(bytes))
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
return fuckitJSON(entity)
}
示例11: DecoderJSONMergePatch
// DecoderJSONMergePatch maps application/merge-patch+json => jsonpatch.Patch
func DecoderJSONMergePatch(r io.Reader, params map[string]string) (interface{}, locale.Error) {
bytes, uerr := ioutil.ReadAll(r)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
var patch jsonpatch.JSONMergePatch
uerr = json.Unmarshal(bytes, &patch)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
return jsonpatch.Patch(patch), nil
}
示例12: Write
func (l decodeJSONError) Write(w io.Writer, loc locale.Spec) locale.Error {
data := map[string]interface{}{
"message": l.message.L10NString(loc),
"diff": l.diff,
}
bytes, uerr := json.Marshal(data)
if uerr != nil {
return locale.UntranslatedError(uerr)
}
_, uerr = w.Write(bytes)
return locale.UntranslatedError(uerr)
}
示例13: GetAllExistingTwilioNumbers
func GetAllExistingTwilioNumbers(cfg *periwinkle.Cfg) []string {
// gets url for the numbers we own in the Twilio Account
incomingNumURL := "https://api.twilio.com/2010-04-01/Accounts/" + cfg.TwilioAccountID + "/IncomingPhoneNumbers.json"
client := &http.Client{}
req, err := http.NewRequest("GET", incomingNumURL, nil)
if err != nil {
periwinkle.LogErr(locale.UntranslatedError(err))
return nil
}
req.SetBasicAuth(cfg.TwilioAccountID, cfg.TwilioAuthToken)
resp, err := client.Do(req)
if err != nil {
periwinkle.LogErr(locale.UntranslatedError(err))
return nil
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
periwinkle.LogErr(locale.UntranslatedError(err))
return nil
}
if resp.StatusCode != 200 {
periwinkle.Logf("Response code %s", resp.Status)
return nil
}
numbers := IncomingNumbers{}
if err := json.Unmarshal(body, &numbers); err != nil {
periwinkle.LogErr(locale.UntranslatedError(err))
return nil
}
if len(numbers.PhoneNumbers) > 0 {
existingNumbers := make([]string, len(numbers.PhoneNumbers))
for i, num := range numbers.PhoneNumbers {
existingNumbers[i] = num.Number
}
return existingNumbers
} else {
return nil
}
}
示例14: fuckitJSON
func fuckitJSON(entity interface{}) (interface{}, locale.Error) {
str, uerr := json.Marshal(entity)
if uerr != nil {
return nil, locale.UntranslatedError(uerr)
}
return json.NewDecoder(strings.NewReader(string(str))), nil
}
示例15: Start
// Start the server; does not block.
func (ss *HTTPServer) Start() {
ss.Server.ConnState = ss.handleConnStateChange
ss.wg.Add(1)
go func() {
defer ss.wg.Done()
ss.err = locale.UntranslatedError(ss.Server.Serve(ss.Socket))
}()
}