Skip to content

Commit 299281b

Browse files
doc: Added godoc style comments for APIs and structs
1 parent 5e402da commit 299281b

File tree

4 files changed

+87
-32
lines changed

4 files changed

+87
-32
lines changed

pkg/httpUtil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This package implements an http client
1+
// This package implements an http client for resource and pokemon APIs from pokeAPI
22
package pokemon
33

44
import (

pkg/pokemon.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This package implements an http client for resource and pokemon APIs from pokeAPI
12
package pokemon
23

34
import (
@@ -6,7 +7,8 @@ import (
67

78
"golang.org/x/exp/slog"
89
)
9-
10+
// Pokemon takes the pokemon id as an integer, send the request with the /pokemon endpoint
11+
// parses the response and returns the Pokemon object and an error if exists
1012
func (c Client) Pokemon(id int) (pokemon Pokemon, err error) {
1113
c.Endpoint = fmt.Sprintf("/pokemon/%d", id)
1214
resp, err := c.sendRequest()

pkg/resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This package implements an http client for resource and pokemon APIs from pokeAPI
12
package pokemon
23

34
import (
@@ -6,6 +7,9 @@ import (
67
"golang.org/x/exp/slog"
78
)
89

10+
// Resource takes optional options, send the request
11+
// with the specified endpoint in the caller client object endpoint
12+
// parses the response and returns the Resource object and an error if exists
913
func (c Client) Resource(options ...int) (resource Resource, err error) {
1014

1115
resp, err := c.sendRequest(options...)

pkg/types.go

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
// This package implements an http client for resource and pokemon APIs from pokeAPI
12
package pokemon
23

4+
// Resource is the resources available for an endpoint
35
type Resource struct {
46
Count int `json:"count"`
57
Next string `json:"next"`
68
Previous string `json:"previous"`
79
Results []Result `json:"results"`
810
}
11+
12+
// Result is a single API resource
913
type Result struct {
1014
Url string `json:"url"`
1115
Name string `json:"name"`
1216
}
1317

18+
// Pokemon holds a single pokemon data
1419
type Pokemon struct {
1520
ID int `json:"id"`
1621
Name string `json:"name"`
@@ -32,72 +37,112 @@ type Pokemon struct {
3237
Stats []PokemonStat `json:"stats"`
3338
Types []PokemonType `json:"types"`
3439
}
35-
type Ability struct {
36-
Name string `json:"name"`
37-
URL string `json:"url"`
38-
}
40+
41+
// PokemonAbility is a single pokemon ability
3942
type PokemonAbility struct {
4043
IsHidden bool `json:"is_hidden"`
4144
Slot int `json:"slot"`
4245
Ability Ability `json:"ability"`
4346
}
44-
type Form struct {
47+
48+
// Ability is an API resource
49+
type Ability struct {
4550
Name string `json:"name"`
4651
URL string `json:"url"`
4752
}
48-
type Version struct {
53+
54+
// Form is a named API resource
55+
type Form struct {
4956
Name string `json:"name"`
5057
URL string `json:"url"`
5158
}
59+
60+
// GameIndex is a single game index
5261
type GameIndex struct {
5362
GameIndex int `json:"game_index"`
5463
Version Version `json:"version"`
5564
}
65+
66+
// Version is a named API resource
67+
type Version struct {
68+
Name string `json:"name"`
69+
URL string `json:"url"`
70+
}
71+
72+
// Item is a named API resource
73+
type Item struct {
74+
Name string `json:"name"`
75+
URL string `json:"url"`
76+
}
77+
78+
// PokemonHeldItem is a single Pokemon item
5679
type PokemonHeldItem struct {
5780
Item Item `json:"item"`
5881
VersionDetails PokemonHeldItemVersion `json:"version_details"`
5982
}
83+
84+
// PokemonHeldItemVersion hold the information about the held item version
6085
type PokemonHeldItemVersion struct {
6186
Version Version `json:"version"`
6287
Rarity int `json:"rarity"`
6388
}
64-
type Move struct {
65-
Name string `json:"name"`
66-
URL string `json:"url"`
67-
}
68-
type Item struct {
69-
Name string `json:"name"`
70-
URL string `json:"url"`
71-
}
89+
90+
// MoveLearnMethod is a named API resource
7291
type MoveLearnMethod struct {
7392
Name string `json:"name"`
7493
URL string `json:"url"`
7594
}
95+
96+
// VersionGroup is a named API resource
7697
type VersionGroup struct {
7798
Name string `json:"name"`
7899
URL string `json:"url"`
79100
}
101+
102+
// PokemonMoveVersion holds the details about the pokemon move versions
80103
type PokemonMoveVersion struct {
81104
MoveLearnMethod MoveLearnMethod `json:"move_learn_method"`
82105
VersionGroup VersionGroup `json:"version_group"`
83106
LevelLearnedAt int `json:"level_learned_at"`
84107
}
108+
109+
// Move is a named API resource
110+
type Move struct {
111+
Name string `json:"name"`
112+
URL string `json:"url"`
113+
}
114+
115+
// PokemonMove is a single pokemon move
85116
type PokemonMove struct {
86117
Move Move `json:"move"`
87118
VersionGroupDetails []PokemonMoveVersion `json:"version_group_details"`
88119
}
120+
121+
// Type is a named API resource
122+
type Type struct {
123+
Name string `json:"name"`
124+
URL string `json:"url"`
125+
}
126+
127+
// PokemonType is a single pokemon type
128+
type PokemonType struct {
129+
Slot int `json:"slot"`
130+
Type Type `json:"type"`
131+
}
132+
133+
// Generation is a named API resource
89134
type Generation struct {
90135
Name string `json:"name"`
91136
URL string `json:"url"`
92137
}
138+
139+
// PokemonTypePast is a single pokemon past type
93140
type PokemonTypePast struct {
94141
Generation Generation `json:"generation"`
95142
Types []PokemonType `json:"types"`
96143
}
97-
type Species struct {
98-
Name string `json:"name"`
99-
URL string `json:"url"`
100-
}
144+
145+
// PokemonSprites holds the details about single pokemon sprites
101146
type PokemonSprites struct {
102147
FrontDefault string `json:"front_default"`
103148
FrontShiny string `json:"front_shiny"`
@@ -108,24 +153,28 @@ type PokemonSprites struct {
108153
BackFemale string `json:"back_female"`
109154
BackShinyFemale string `json:"back_shiny_female"`
110155
}
156+
157+
// PokemonCries holds the details about single pokemon cries
158+
type PokemonCries struct {
159+
Latest string `json:"latest"`
160+
Legacy string `json:"legacy"`
161+
}
162+
163+
// Species is a named API resource
164+
type Species struct {
165+
Name string `json:"name"`
166+
URL string `json:"url"`
167+
}
168+
169+
// Stat is a named API resource
111170
type Stat struct {
112171
Name string `json:"name"`
113172
URL string `json:"url"`
114173
}
174+
175+
// PokemonStat holds the details about single pokemon stats
115176
type PokemonStat struct {
116177
Stat Stat `json:"stat"`
117178
BaseStat int `json:"base_stat"`
118179
Effort int `json:"effort"`
119180
}
120-
type Type struct {
121-
Name string `json:"name"`
122-
URL string `json:"url"`
123-
}
124-
type PokemonType struct {
125-
Slot int `json:"slot"`
126-
Type Type `json:"type"`
127-
}
128-
type PokemonCries struct {
129-
Latest string `json:"latest"`
130-
Legacy string `json:"legacy"`
131-
}

0 commit comments

Comments
 (0)