-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.go
61 lines (49 loc) · 2 KB
/
server.go
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
// Package ud859 is an implementation of the udacity course at http://udacity.com/course/ud859.
package ud859
import "github.com/GoogleCloudPlatform/go-endpoints/endpoints"
const clientID = "YOUR-CLIENT-ID"
var (
scopes = []string{endpoints.EmailScope}
clientIds = []string{clientID, endpoints.APIExplorerClientID}
audiences = []string{clientID}
)
// ConferenceAPI defines the conferences management API.
type ConferenceAPI struct{}
func init() {
server := endpoints.NewServer("")
if err := RegisterConferenceAPI(server); err != nil {
panic(err)
}
server.HandleHTTP(nil)
}
// RegisterConferenceAPI adds the ConferenceAPI to the server.
func RegisterConferenceAPI(server *endpoints.Server) error {
api, err := server.RegisterService(
new(ConferenceAPI), "conference", "v1", "Conference Central", true)
if err != nil {
return err
}
register := func(orig, name, method, path string) *endpoints.MethodInfo {
info := api.MethodByName(orig).Info()
info.Name, info.HTTPMethod, info.Path = name, method, path
return info
}
login := func(orig, name, method, path string) {
info := register(orig, name, method, path)
info.Scopes, info.ClientIds, info.Audiences = scopes, clientIds, audiences
}
// profile
login("GetProfile", "getProfile", "GET", "profile")
login("SaveProfile", "saveProfile", "POST", "profile")
// conference
register("GetConference", "getConference", "GET", "conference/{websafeConferenceKey}")
login("CreateConference", "createConference", "POST", "conference")
// query conferences
login("ConferencesCreated", "getConferencesCreated", "POST", "getConferencesCreated")
login("ConferencesToAttend", "getConferencesToAttend", "GET", "getConferencesToAttend")
register("QueryConferences", "queryConferences", "POST", "queryConferences")
// registration
login("GotoConference", "registerForConference", "POST", "conference/{websafeConferenceKey}/registration")
login("CancelConference", "unregisterFromConference", "DELETE", "conference/{websafeConferenceKey}/registration")
return nil
}