refactor: Replace interface{} with any alias and optimize string formatting with fmt.Appendf

- Replace map[string]interface{} with map[string]any in GraphQL, metrics, payment gateway, and webhook handlers
- Replace []byte(fmt.Sprintf()) with fmt.Appendf(nil, ...) for cursor encoding in GraphQL resolvers and tests
- Replace strings.HasPrefix/TrimPrefix with strings.CutPrefix for webhook signature parsing
- Replace stripe.Int64/Bool with new() constructor for Stripe payment parameters
- Rename Error
This commit is contained in:
nutcas3
2026-04-23 02:56:24 +03:00
parent a839b1cde5
commit d114f1960f
8 changed files with 58 additions and 57 deletions
@@ -370,6 +370,6 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
return nil
}
func (e *executableSchema) Extensions() map[string]interface{} {
return map[string]interface{}{}
func (e *executableSchema) Extensions() map[string]any {
return map[string]any{}
}
@@ -54,8 +54,8 @@ func strPtr(s string) *string { return new(s) }
func buildConnectionPageInfo(offset, count int, total int64) *PageInfo {
var startCursor, endCursor *string
if count > 0 {
startCursor = strPtr(base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", offset+1))))
endCursor = strPtr(base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", offset+count))))
startCursor = strPtr(base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "%d", offset+1)))
endCursor = strPtr(base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "%d", offset+count)))
}
return &PageInfo{
HasNextPage: int64(offset+count) < total,
@@ -104,7 +104,7 @@ func (r *Resolver) Subscribers(ctx context.Context, first *int, after *string, f
s := sub // avoid loop-variable capture
edges[i] = &SubscriberEdge{
Node: &s,
Cursor: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", offset+i+1))),
Cursor: base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "%d", offset+i+1)),
}
}
@@ -143,7 +143,7 @@ func (r *Resolver) UsageEvents(ctx context.Context, first *int, after *string, i
for i, event := range events {
edges[i] = &UsageEventEdge{
Node: event,
Cursor: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", offset+i+1))),
Cursor: base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "%d", offset+i+1)),
}
}
@@ -225,7 +225,7 @@ func (r *Resolver) Invoices(ctx context.Context, first *int, after *string, imsi
for i, inv := range invoices {
edges[i] = &InvoiceEdge{
Node: inv,
Cursor: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", offset+i+1))),
Cursor: base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "%d", offset+i+1)),
}
}
@@ -271,7 +271,7 @@ func (r *Resolver) Alerts(ctx context.Context, first *int, after *string, subscr
for i, alert := range alerts {
edges[i] = &AlertEdge{
Node: alert,
Cursor: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", offset+i+1))),
Cursor: base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "%d", offset+i+1)),
}
}
@@ -118,7 +118,7 @@ func TestResolverRoot_Methods(t *testing.T) {
// Helper functions for testing (these should match the implementations in resolvers.go)
func encodeCursor(offset int) string {
return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("cursor:%d", offset)))
return base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "cursor:%d", offset))
}
func decodeCursor(cursor string) (int, error) {