chore: initial import from sless/shared-sqs (v0.1.14)
- Standalone SQS-service repository - Multi-tenant message queue service, AWS SQS compatible - Based on GoAws, with mutable tenants, auth, WebUI, Redis persistence - Ready for independent development and deployment - See doc/ and README.md for architecture and usage
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// StringToInt this is a custom type that will allow our request bodies to support either a string OR an int.
|
||||
// It has its own UnmarshalJSON method to handle both types automatically and it can return an `int`
|
||||
// from the `Int` method.
|
||||
type StringToInt int
|
||||
|
||||
func (s *StringToInt) UnmarshalJSON(data []byte) error {
|
||||
var i int
|
||||
err := json.Unmarshal(data, &i)
|
||||
if err == nil {
|
||||
*s = StringToInt(i)
|
||||
return nil
|
||||
}
|
||||
|
||||
var str string
|
||||
err = json.Unmarshal(data, &str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmp, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*s = StringToInt(tmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StringToInt) Int() int {
|
||||
return int(*s)
|
||||
}
|
||||
Reference in New Issue
Block a user