Files
SQS-service/app/models/conversions.go
T
Repinoid 9f1242aca3 feat(aws-compat): queue attributes for Terraform (FifoQueue, ContentBasedDeduplication, Policy, real timestamps)
- GetQueueAttributes now returns FifoQueue, ContentBasedDeduplication, Policy and
  real Created/LastModifiedTimestamp (previously missing/stubbed '0000000000')
- Queue: add CreatedAt, LastModifiedAt, Policy, ContentBasedDeduplication
- parse FifoQueue/ContentBasedDeduplication in both protocols (StringToBool)
- Policy/RedriveAllowPolicy: normalize JSON-string form to object (JSON protocol
  sent them as string -> SetQueueAttributes failed with InvalidParameterValue)
- persistence: keep new fields in meta DTO + backfill empty timestamps on load
- FIFO dedup is inherent: IsDuplicate/InitDuplicatation gate on IsFIFO only
  (env flag EnableDuplicates=false disabled dedup for all FIFO queues)
2026-10-10 17:29:58 +03:00

65 lines
1.5 KiB
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)
}
// StringToBool — аналог StringToInt для булевых атрибутов: принимает и JSON-bool
// (true/false), и строку ("true"/"false"). Query-протокол шлёт строки,
// JSON-протокол — булевы значения; без этого FifoQueue/ContentBasedDeduplication
// из JSON-запроса молча терялись бы.
type StringToBool bool
func (s *StringToBool) UnmarshalJSON(data []byte) error {
var b bool
if err := json.Unmarshal(data, &b); err == nil {
*s = StringToBool(b)
return nil
}
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
tmp, err := strconv.ParseBool(str)
if err != nil {
return err
}
*s = StringToBool(tmp)
return nil
}
func (s *StringToBool) Bool() bool {
return bool(*s)
}