azimuth-client-go/examples_test.go
2025-09-16 23:42:51 -07:00

168 lines
4.6 KiB
Go

package azimuth_test
import (
"fmt"
"log"
azimuth "git.vdb.to/LaconicNetwork/azimuth-client-go"
)
func ExampleNewClient() {
// Create client with default endpoint
_ = azimuth.NewClient("")
// Or with custom endpoint
_ = azimuth.NewClient("https://azimuth.dev.vdb.to")
fmt.Printf("Client created with contract address: %s\n", azimuth.AzimuthContract)
// Output: Client created with contract address: 0x223c067F8CF28ae173EE5CafEa60cA44C335fecB
}
func ExampleNewClientWithOptions() {
// Create client with custom options
_ = azimuth.NewClientWithOptions(azimuth.ClientOptions{
Endpoint: "https://custom.azimuth.endpoint.com/graphql",
CacheTTL: azimuth.DefaultCacheTTL * 2, // 2 hours
ContractAddress: azimuth.AzimuthContract,
Timeout: azimuth.DefaultTimeout,
})
fmt.Printf("Custom client created\n")
// Output: Custom client created
}
func ExampleGetShipType() {
// Classify different ship types
fmt.Printf("Point 0 is a %s\n", azimuth.GetShipType(0)) // Galaxy
fmt.Printf("Point 256 is a %s\n", azimuth.GetShipType(256)) // Star
fmt.Printf("Point 65536 is a %s\n", azimuth.GetShipType(65536)) // Planet
// Output:
// Point 0 is a galaxy
// Point 256 is a star
// Point 65536 is a planet
}
func ExampleParseShipName() {
// Parse numeric ship names
point, err := azimuth.ParseShipName("256")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Ship name '256' -> point %d\n", point)
// Parse with tilde prefix
point, err = azimuth.ParseShipName("~256")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Ship name '~256' -> point %d\n", point)
// Output:
// Ship name '256' -> point 256
// Ship name '~256' -> point 256
}
func ExampleParseStarID() {
// Parse and validate star ID
starID, err := azimuth.ParseStarID("256")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Valid star ID: %d\n", starID)
// This would return an error since 255 is a galaxy
_, err = azimuth.ParseStarID("255")
if err != nil {
fmt.Printf("Error for galaxy: %s\n", err.Error())
}
// Output:
// Valid star ID: 256
// Error for galaxy: ID 255 is not a valid star (must be 256-65535)
}
func ExampleClient_GetAuthenticationKey() {
// This is a mock example - would require real azimuth-watcher endpoint
fmt.Printf("Getting authentication key for point 256...\n")
// In a real scenario:
// client := azimuth.NewClient("")
// ctx := context.Background()
// authKey, err := client.GetAuthenticationKey(ctx, 256)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("Authentication key: %x\n", authKey)
// Output: Getting authentication key for point 256...
}
func ExampleClient_GetShipKeys() {
// This is a mock example - would require real azimuth-watcher endpoint
fmt.Printf("Getting all keys for point 256...\n")
// In a real scenario:
// client := azimuth.NewClient("")
// ctx := context.Background()
// keys, err := client.GetShipKeys(ctx, 256)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("Encryption key: %x\n", keys.EncryptionKey)
// fmt.Printf("Authentication key: %x\n", keys.AuthenticationKey)
// fmt.Printf("Crypto suite version: %d\n", keys.CryptoSuiteVersion)
// fmt.Printf("Key revision number: %d\n", keys.KeyRevisionNumber)
// Output: Getting all keys for point 256...
}
func ExampleClient_IsShipActive() {
// This is a mock example - would require real azimuth-watcher endpoint
fmt.Printf("Checking if point 256 is active...\n")
// In a real scenario:
// client := azimuth.NewClient("")
// ctx := context.Background()
// active, err := client.IsShipActive(ctx, 256)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("Point 256 is active: %t\n", active)
// Output: Checking if point 256 is active...
}
func ExampleClient_GetSponsor() {
// This is a mock example - would require real azimuth-watcher endpoint
fmt.Printf("Getting sponsor for star 256...\n")
// In a real scenario:
// client := azimuth.NewClient("")
// ctx := context.Background()
// sponsor, err := client.GetSponsor(ctx, 256)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("Star 256 is sponsored by galaxy %d\n", sponsor)
// Output: Getting sponsor for star 256...
}
func ExampleValidateStarSponsorship() {
// This is a mock example - would require real azimuth-watcher endpoint
fmt.Printf("Validating star 256 is sponsored by galaxy 0...\n")
// In a real scenario:
// client := azimuth.NewClient("")
// ctx := context.Background()
// err := azimuth.ValidateStarSponsorship(ctx, 256, 0, client)
// if err != nil {
// fmt.Printf("Validation failed: %s\n", err.Error())
// } else {
// fmt.Printf("Validation successful!\n")
// }
// Output: Validating star 256 is sponsored by galaxy 0...
}