-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (49 loc) · 1.22 KB
/
main.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
package backend
import (
"fmt"
"net/http"
"reflect"
"strings"
"github.com/favclip/ucon"
"github.com/favclip/ucon/swagger"
)
func Setup() {
ucon.Orthodox()
ucon.Middleware(swagger.RequestValidator())
swPlugin := swagger.NewPlugin(&swagger.Options{
Object: &swagger.Object{
Info: &swagger.Info{
Title: "GCPUG",
Version: "v1",
},
Schemes: []string{"http", "https"},
},
DefinitionNameModifier: func(refT reflect.Type, defName string) string {
if strings.HasSuffix(defName, "JSON") {
return defName[:len(defName)-4]
}
return defName
},
})
ucon.Plugin(swPlugin)
setupSpannerAccountAPI(swPlugin)
http.Handle("/api/", ucon.DefaultMux)
ucon.DefaultMux.Prepare()
}
// HTTPError is API Resposeとして返すError
type HTTPError struct {
Code int `json:"code"`
Message interface{} `json:"message"`
}
// StatusCode is Http Response Status Codeを返す
func (he *HTTPError) StatusCode() int {
return he.Code
}
// ErrorMessage is Clientに返すErrorMessageを返す
func (he *HTTPError) ErrorMessage() interface{} {
return he
}
// Error is error interfaceを実装
func (he *HTTPError) Error() string {
return fmt.Sprintf("status code %d: %s", he.StatusCode(), he.ErrorMessage())
}