-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstarting.go
More file actions
102 lines (92 loc) · 2.82 KB
/
starting.go
File metadata and controls
102 lines (92 loc) · 2.82 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
96
97
98
99
100
101
102
package main
import (
"fmt"
"log"
"net/http"
)
type Type struct {
// Name of the type
Name string `json:"name"`
// The effective types, damage multiplize 2x
EffectiveAgainst []string `json:"effectiveAgainst"`
// The weak types that against, damage multiplize 0.5x
WeakAgainst []string `json:"weakAgainst"`
}
type Pokemon struct {
Number string `json:"Number"`
Name string `json:"Name"`
Classification string `json:"Classification"`
TypeI []string `json:"Type I"`
TypeII []string `json:"Type II,omitempty"`
Weaknesses []string `json:"Weaknesses"`
FastAttackS []string `json:"Fast Attack(s)"`
Weight string `json:"Weight"`
Height string `json:"Height"`
Candy struct {
Name string `json:"Name"`
FamilyID int `json:"FamilyID"`
} `json:"Candy"`
NextEvolutionRequirements struct {
Amount int `json:"Amount"`
Family int `json:"Family"`
Name string `json:"Name"`
} `json:"Next Evolution Requirements,omitempty"`
NextEvolutions []struct {
Number string `json:"Number"`
Name string `json:"Name"`
} `json:"Next evolution(s),omitempty"`
PreviousEvolutions []struct {
Number string `json:"Number"`
Name string `json:"Name"`
} `json:"Previous evolution(s),omitempty"`
SpecialAttacks []string `json:"Special Attack(s)"`
BaseAttack int `json:"BaseAttack"`
BaseDefense int `json:"BaseDefense"`
BaseStamina int `json:"BaseStamina"`
CaptureRate float64 `json:"CaptureRate"`
FleeRate float64 `json:"FleeRate"`
BuddyDistanceNeeded int `json:"BuddyDistanceNeeded"`
}
// Move is an attack information. The
type Move struct {
// The ID of the move
ID int `json:"id"`
// Name of the attack
Name string `json:"name"`
// Type of attack
Type string `json:"type"`
// The damage that enemy will take
Damage int `json:"damage"`
// Energy requirement of the attack
Energy int `json:"energy"`
// Dps is Damage Per Second
Dps float64 `json:"dps"`
// The duration
Duration int `json:"duration"`
}
// BaseData is a struct for reading data.json
type BaseData struct {
Types []Type `json:"types"`
Pokemons []Pokemon `json:"pokemons"`
Moves []Move `json:"moves"`
}
func listHandler(w http.ResponseWriter, r *http.Request) {
log.Println("/list url:", r.URL)
fmt.Fprint(w, "The List Handler\n")
}
func getHandler(w http.ResponseWriter, r *http.Request) {
log.Println("/get url:", r.URL)
fmt.Fprint(w, "The Get Handler\n")
}
func otherwise(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello World\n")
}
func main() {
//TODO: read data.json to a BaseData
http.HandleFunc("/list", listHandler)
http.HandleFunc("/get", getHandler)
//TODO: add more
http.HandleFunc("/", otherwise)
log.Println("starting server on :8080")
http.ListenAndServe(":8080", nil)
}