-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
95 lines (87 loc) · 3.36 KB
/
client.go
File metadata and controls
95 lines (87 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package astroapi
import (
"os"
"github.com/astro-api/astroapi-go/categories"
"github.com/astro-api/astroapi-go/categories/analysis"
"github.com/astro-api/astroapi-go/categories/astrocartography"
"github.com/astro-api/astroapi-go/categories/charts"
"github.com/astro-api/astroapi-go/categories/chinese"
"github.com/astro-api/astroapi-go/categories/data"
"github.com/astro-api/astroapi-go/categories/eclipses"
"github.com/astro-api/astroapi-go/categories/enhanced"
"github.com/astro-api/astroapi-go/categories/fixedstars"
"github.com/astro-api/astroapi-go/categories/glossary"
"github.com/astro-api/astroapi-go/categories/horoscope"
"github.com/astro-api/astroapi-go/categories/insights"
"github.com/astro-api/astroapi-go/categories/lunar"
"github.com/astro-api/astroapi-go/categories/numerology"
"github.com/astro-api/astroapi-go/categories/svg"
"github.com/astro-api/astroapi-go/categories/tarot"
"github.com/astro-api/astroapi-go/categories/traditional"
"github.com/astro-api/astroapi-go/internal/requestconfig"
"github.com/astro-api/astroapi-go/option"
)
// AstrologyClient is the root client for the Astrology API.
// Create one with NewClient() and use the sub-clients to call specific endpoints.
type AstrologyClient struct {
Data *data.Client
Charts *charts.Client
Horoscope *horoscope.Client
Analysis *analysis.Client
Glossary *glossary.Client
Astrocartography *astrocartography.Client
Chinese *chinese.Client
Eclipses *eclipses.Client
Lunar *lunar.Client
Numerology *numerology.Client
Tarot *tarot.Client
Traditional *traditional.Client
FixedStars *fixedstars.Client
Insights *insights.Client
SVG *svg.Client
Enhanced *enhanced.Client
cfg *requestconfig.RequestConfig
}
// NewClient creates a new AstrologyClient. Configuration defaults are applied
// first, then options in order, then environment variable fallbacks.
//
// client := astroapi.NewClient(
// option.WithAPIKey("your-api-key"),
// )
func NewClient(opts ...option.RequestOption) *AstrologyClient {
cfg := requestconfig.NewDefault()
rawOpts := make([]func(*requestconfig.RequestConfig), len(opts))
for i, o := range opts {
rawOpts[i] = o
}
cfg.Apply(rawOpts)
// Environment variable fallbacks.
if cfg.APIKey == "" {
cfg.APIKey = os.Getenv("ASTROLOGY_API_KEY")
}
if cfg.BaseURL == "" || cfg.BaseURL == requestconfig.DefaultBaseURL {
if envURL := os.Getenv("ASTROLOGY_API_BASE_URL"); envURL != "" {
cfg.BaseURL = envURL
}
}
base := &categories.BaseCategoryClient{Config: cfg}
return &AstrologyClient{
cfg: cfg,
Data: data.NewClient(base),
Charts: charts.NewClient(base),
Horoscope: horoscope.NewClient(base),
Analysis: analysis.NewClient(base),
Glossary: glossary.NewClient(base),
Astrocartography: astrocartography.NewClient(base),
Chinese: chinese.NewClient(base),
Eclipses: eclipses.NewClient(base),
Lunar: lunar.NewClient(base),
Numerology: numerology.NewClient(base),
Tarot: tarot.NewClient(base),
Traditional: traditional.NewClient(base),
FixedStars: fixedstars.NewClient(base),
Insights: insights.NewClient(base),
SVG: svg.NewClient(base),
Enhanced: enhanced.NewClient(base),
}
}