Files
SQS-service/app/models/conversions.go
T
Naeel c3ba2dcae4 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
2026-04-10 16:47:27 +03:00

37 lines
709 B
Go

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)
}