- Consolidated azimuth client implementations from zenithd and janus - Type-safe GraphQL client using genqlient code generation - Comprehensive caching with configurable TTL (1 hour default) - Full API coverage: authentication keys, ship activity, sponsorship, ownership - Enhanced functionality combining best features from both original implementations - Extensive test suite with 16 unit tests covering all functionality - Complete documentation with examples and usage patterns - Support for galaxy, star, and planet ship type classification - BigInt utility for proper GraphQL number handling - MIT licensed for open source usage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package azimuth
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
"strings"
|
|
)
|
|
|
|
// BigInt is a wrapper around big.Int that implements JSON marshaling for GraphQL
|
|
type BigInt struct {
|
|
big.Int
|
|
}
|
|
|
|
// NewBigInt creates a new BigInt from an int64
|
|
func NewBigInt(value int64) BigInt {
|
|
return BigInt{Int: *big.NewInt(value)}
|
|
}
|
|
|
|
// NewBigIntFromUint32 creates a new BigInt from a uint32
|
|
func NewBigIntFromUint32(value uint32) BigInt {
|
|
return BigInt{Int: *big.NewInt(int64(value))}
|
|
}
|
|
|
|
// MarshalJSON implements json.Marshaler for GraphQL serialization
|
|
func (b BigInt) MarshalJSON() ([]byte, error) {
|
|
return []byte(b.String()), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler for GraphQL deserialization
|
|
func (b *BigInt) UnmarshalJSON(p []byte) error {
|
|
// The output is string with escaped quotes
|
|
cleanedStr := strings.Trim(string(p), `"`)
|
|
if cleanedStr == "null" {
|
|
return nil
|
|
}
|
|
|
|
var z big.Int
|
|
_, ok := z.SetString(cleanedStr, 10)
|
|
if !ok {
|
|
return fmt.Errorf("not a valid big integer: %s", p)
|
|
}
|
|
b.Int = z
|
|
|
|
return nil
|
|
}
|
|
|
|
// ToUint32 converts BigInt to uint32, returns error if out of range
|
|
func (b BigInt) ToUint32() (uint32, error) {
|
|
if !b.IsUint64() {
|
|
return 0, fmt.Errorf("value is too large for uint32: %s", b.String())
|
|
}
|
|
|
|
val := b.Uint64()
|
|
if val > 0xFFFFFFFF {
|
|
return 0, fmt.Errorf("value is too large for uint32: %d", val)
|
|
}
|
|
|
|
return uint32(val), nil
|
|
} |