Skip to content

Commit 26e054e

Browse files
committed
Fixup documentation style to be consistent
1 parent 0b829b4 commit 26e054e

File tree

8 files changed

+89
-88
lines changed

8 files changed

+89
-88
lines changed

api.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,6 @@ type resource struct {
191191
marshalers map[string]ContentMarshaler
192192
}
193193

194-
// AddResource registers a data source for the given resource
195-
// At least the CRUD interface must be implemented, all the other interfaces are optional.
196-
// `resource` should be either an empty struct instance such as `Post{}` or a pointer to
197-
// a struct such as `&Post{}`. The same type will be used for constructing new elements.
198-
func (api *API) AddResource(prototype jsonapi.MarshalIdentifier, source CRUD) {
199-
api.addResource(prototype, source, api.marshalers)
200-
}
201-
202-
// UseMiddleware registers middlewares that implement the api2go.HandlerFunc
203-
// Middleware is run before any generated routes.
204-
func (api *API) UseMiddleware(middleware ...HandlerFunc) {
205-
api.middlewares = append(api.middlewares, middleware...)
206-
}
207-
208194
// middlewareChain executes the middleeware chain setup
209195
func (api *API) middlewareChain(c APIContexter, w http.ResponseWriter, r *http.Request) {
210196
for _, middleware := range api.middlewares {

api_interfaces.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ type URLResolver interface {
6363
GetBaseURL() string
6464
}
6565

66-
//RequestAwareURLResolver allows you to dynamically change
67-
//generated urls.
66+
// RequestAwareURLResolver allows you to dynamically change
67+
// generated urls.
6868
//
69-
//This is particulary useful if you have the same
70-
//API answering to multiple domains, or subdomains
71-
//e.g customer[1,2,3,4].yourapi.example.com
69+
// This is particulary useful if you have the same
70+
// API answering to multiple domains, or subdomains
71+
// e.g customer[1,2,3,4].yourapi.example.com
7272
//
73-
//SetRequest will always be called prior to
74-
//the GetBaseURL() from `URLResolver` so you
75-
//have to change the result value based on the last
76-
//request.
73+
// SetRequest will always be called prior to
74+
// the GetBaseURL() from `URLResolver` so you
75+
// have to change the result value based on the last
76+
// request.
7777
type RequestAwareURLResolver interface {
7878
URLResolver
7979
SetRequest(http.Request)

api_public.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"sync"
77

8+
"github.com/manyminds/api2go/jsonapi"
89
"github.com/manyminds/api2go/routing"
910
)
1011

@@ -44,10 +45,24 @@ func (api *API) SetContextAllocator(allocator APIContextAllocatorFunc) {
4445
api.contextAllocator = allocator
4546
}
4647

47-
//SetRedirectTrailingSlash enables 307 redirects on urls ending with /
48-
//when disabled, an URL ending with / will 404
49-
//this will and should work only if using the default router
50-
//DEPRECATED
48+
// AddResource registers a data source for the given resource
49+
// At least the CRUD interface must be implemented, all the other interfaces are optional.
50+
// `resource` should be either an empty struct instance such as `Post{}` or a pointer to
51+
// a struct such as `&Post{}`. The same type will be used for constructing new elements.
52+
func (api *API) AddResource(prototype jsonapi.MarshalIdentifier, source CRUD) {
53+
api.addResource(prototype, source, api.marshalers)
54+
}
55+
56+
// UseMiddleware registers middlewares that implement the api2go.HandlerFunc
57+
// Middleware is run before any generated routes.
58+
func (api *API) UseMiddleware(middleware ...HandlerFunc) {
59+
api.middlewares = append(api.middlewares, middleware...)
60+
}
61+
62+
// SetRedirectTrailingSlash enables 307 redirects on urls ending with /
63+
// when disabled, an URL ending with / will 404
64+
// this will and should work only if using the default router
65+
// DEPRECATED
5166
func (api *API) SetRedirectTrailingSlash(enabled bool) {
5267
if api.router == nil {
5368
panic("router must not be nil")
@@ -86,21 +101,21 @@ func NewAPI(prefix string) *API {
86101
return NewAPIWithMarshalers(prefix, "", DefaultContentMarshalers)
87102
}
88103

89-
//NewAPIWithRouting allows you to use a custom URLResolver, marshalers and custom routing
90-
//if you want to use the default routing, you should use another constructor.
104+
// NewAPIWithRouting allows you to use a custom URLResolver, marshalers and custom routing
105+
// if you want to use the default routing, you should use another constructor.
91106
//
92-
//If you don't need any of the parameters you can skip them with the defaults:
93-
//the default for `prefix` would be `""`, which means there is no namespace for your api.
94-
//although we suggest using one.
107+
// If you don't need any of the parameters you can skip them with the defaults:
108+
// the default for `prefix` would be `""`, which means there is no namespace for your api.
109+
// although we suggest using one.
95110
//
96-
//if your api only answers to one url you can use a NewStaticResolver() as `resolver`
111+
// if your api only answers to one url you can use a NewStaticResolver() as `resolver`
97112
//
98-
//if you have no specific marshalling needs, use `DefaultContentMarshalers`
113+
// if you have no specific marshalling needs, use `DefaultContentMarshalers`
99114
func NewAPIWithRouting(prefix string, resolver URLResolver, marshalers map[string]ContentMarshaler, router routing.Routeable) *API {
100115
return newAPI(prefix, resolver, marshalers, router)
101116
}
102117

103-
//newAPI is now an internal method that can be changed if params are changing
118+
// newAPI is now an internal method that can be changed if params are changing
104119
func newAPI(prefix string, resolver URLResolver, marshalers map[string]ContentMarshaler, router routing.Routeable) *API {
105120
if len(marshalers) == 0 {
106121
panic("marshaler map must not be empty")
@@ -134,8 +149,8 @@ func newAPI(prefix string, resolver URLResolver, marshalers map[string]ContentMa
134149
return api
135150
}
136151

137-
//NewAPIWithMarshalers is DEPRECATED
138-
//use NewApiWithMarshalling instead
152+
// NewAPIWithMarshalers is DEPRECATED
153+
// use NewApiWithMarshalling instead
139154
func NewAPIWithMarshalers(prefix string, baseURL string, marshalers map[string]ContentMarshaler) *API {
140155
staticResolver := NewStaticResolver(baseURL)
141156
return NewAPIWithMarshalling(prefix, staticResolver, marshalers)

error.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import (
66
"strconv"
77
)
88

9-
//HTTPError is used for errors
9+
// HTTPError is used for errors
1010
type HTTPError struct {
1111
err error
1212
msg string
1313
status int
1414
Errors []Error `json:"errors,omitempty"`
1515
}
1616

17-
//Error can be used for all kind of application errors
18-
//e.g. you would use it to define form errors or any
19-
//other semantical application problems
20-
//for more information see http://jsonapi.org/format/#errors
17+
// Error can be used for all kind of application errors
18+
// e.g. you would use it to define form errors or any
19+
// other semantical application problems
20+
// for more information see http://jsonapi.org/format/#errors
2121
type Error struct {
2222
ID string `json:"id,omitempty"`
2323
Links *ErrorLinks `json:"links,omitempty"`
@@ -34,28 +34,28 @@ func (e Error) GetID() string {
3434
return e.ID
3535
}
3636

37-
//ErrorLinks is used to provide an About URL that leads to
38-
//further details about the particular occurrence of the problem.
37+
// ErrorLinks is used to provide an About URL that leads to
38+
// further details about the particular occurrence of the problem.
3939
//
40-
//for more information see http://jsonapi.org/format/#error-objects
40+
// for more information see http://jsonapi.org/format/#error-objects
4141
type ErrorLinks struct {
4242
About string `json:"about,omitempty"`
4343
}
4444

45-
//ErrorSource is used to provide references to the source of an error.
45+
// ErrorSource is used to provide references to the source of an error.
4646
//
47-
//The Pointer is a JSON Pointer to the associated entity in the request
48-
//document.
49-
//The Paramter is a string indicating which query parameter caused the error.
47+
// The Pointer is a JSON Pointer to the associated entity in the request
48+
// document.
49+
// The Paramter is a string indicating which query parameter caused the error.
5050
//
51-
//for more information see http://jsonapi.org/format/#error-objects
51+
// for more information see http://jsonapi.org/format/#error-objects
5252
type ErrorSource struct {
5353
Pointer string `json:"pointer,omitempty"`
5454
Parameter string `json:"parameter,omitempty"`
5555
}
5656

57-
//MarshalError marshals errors recursively in json format.
58-
//it can make use of the jsonapi.HTTPError struct
57+
// MarshalError marshals errors recursively in json format.
58+
// it can make use of the jsonapi.HTTPError struct
5959
func (j JSONContentMarshaler) MarshalError(err error) string {
6060
httpErr, ok := err.(HTTPError)
6161
if ok {
@@ -67,7 +67,7 @@ func (j JSONContentMarshaler) MarshalError(err error) string {
6767
return marshalHTTPError(httpErr, j)
6868
}
6969

70-
//marshalHTTPError marshals an internal httpError
70+
// marshalHTTPError marshals an internal httpError
7171
func marshalHTTPError(input HTTPError, marshaler ContentMarshaler) string {
7272
if len(input.Errors) == 0 {
7373
input.Errors = []Error{{Title: input.msg, Status: strconv.Itoa(input.status)}}
@@ -90,7 +90,7 @@ func NewHTTPError(err error, msg string, status int) HTTPError {
9090
return HTTPError{err: err, msg: msg, status: status}
9191
}
9292

93-
//Error returns a nice string represenation including the status
93+
// Error returns a nice string represenation including the status
9494
func (e HTTPError) Error() string {
9595
msg := fmt.Sprintf("http error (%d) %s and %d more errors", e.status, e.msg, len(e.Errors))
9696
if e.err != nil {

resolver.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ type callbackResolver struct {
77
r http.Request
88
}
99

10-
//NewCallbackResolver handles each resolve via
11-
//your provided callback func
10+
// NewCallbackResolver handles each resolve via
11+
// your provided callback func
1212
func NewCallbackResolver(callback func(http.Request) string) URLResolver {
1313
return &callbackResolver{callback: callback}
1414
}
1515

16-
//GetBaseURL calls the callback given in the constructor method
17-
//to implement `URLResolver`
16+
// GetBaseURL calls the callback given in the constructor method
17+
// to implement `URLResolver`
1818
func (c callbackResolver) GetBaseURL() string {
1919
return c.callback(c.r)
2020
}
2121

22-
//SetRequest to implement `RequestAwareURLResolver`
22+
// SetRequest to implement `RequestAwareURLResolver`
2323
func (c *callbackResolver) SetRequest(r http.Request) {
2424
c.r = r
2525
}
2626

27-
//staticResolver is only used
28-
//for backwards compatible reasons
29-
//and might be removed in the future
27+
// staticResolver is only used
28+
// for backwards compatible reasons
29+
// and might be removed in the future
3030
type staticResolver struct {
3131
baseURL string
3232
}
@@ -35,8 +35,8 @@ func (s staticResolver) GetBaseURL() string {
3535
return s.baseURL
3636
}
3737

38-
//NewStaticResolver returns a simple resolver that
39-
//will always answer with the same url
38+
// NewStaticResolver returns a simple resolver that
39+
// will always answer with the same url
4040
func NewStaticResolver(baseURL string) URLResolver {
4141
return &staticResolver{baseURL: baseURL}
4242
}

response.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package api2go
22

3-
//The Response struct implements api2go.Responder and can be used as a default
4-
//implementation for your responses
5-
//you can fill the field `Meta` with all the metadata your application needs
6-
//like license, tokens, etc
3+
// The Response struct implements api2go.Responder and can be used as a default
4+
// implementation for your responses
5+
// you can fill the field `Meta` with all the metadata your application needs
6+
// like license, tokens, etc
77
type Response struct {
88
Res interface{}
99
Code int

routing/httprouter.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"github.com/julienschmidt/httprouter"
77
)
88

9-
//HTTPRouter default router implementation for api2go
9+
// HTTPRouter default router implementation for api2go
1010
type HTTPRouter struct {
1111
router *httprouter.Router
1212
}
1313

14-
//Handle each method like before and wrap them into julienschmidt handler func style
14+
// Handle each method like before and wrap them into julienschmidt handler func style
1515
func (h HTTPRouter) Handle(protocol, route string, handler HandlerFunc) {
1616
wrappedCallback := func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
1717
params := map[string]string{}
@@ -25,26 +25,26 @@ func (h HTTPRouter) Handle(protocol, route string, handler HandlerFunc) {
2525
h.router.Handle(protocol, route, wrappedCallback)
2626
}
2727

28-
//Handler returns the router
28+
// Handler returns the router
2929
func (h HTTPRouter) Handler() http.Handler {
3030
return h.router
3131
}
3232

33-
//SetRedirectTrailingSlash wraps this internal functionality of
34-
//the julienschmidt router.
33+
// SetRedirectTrailingSlash wraps this internal functionality of
34+
// the julienschmidt router.
3535
func (h HTTPRouter) SetRedirectTrailingSlash(enabled bool) {
3636
h.router.RedirectTrailingSlash = enabled
3737
}
3838

39-
//GetRouteParameter implemention will extract the param the julienschmidt way
39+
// GetRouteParameter implemention will extract the param the julienschmidt way
4040
func (h HTTPRouter) GetRouteParameter(r http.Request, param string) string {
4141
path := httprouter.CleanPath(r.URL.Path)
4242
_, params, _ := h.router.Lookup(r.Method, path)
4343
return params.ByName(param)
4444
}
4545

46-
//NewHTTPRouter returns a new instance of julienschmidt/httprouter
47-
//this is the default router when using api2go
46+
// NewHTTPRouter returns a new instance of julienschmidt/httprouter
47+
// this is the default router when using api2go
4848
func NewHTTPRouter(prefix string, notAllowedHandler http.Handler) Routeable {
4949
router := httprouter.New()
5050
router.HandleMethodNotAllowed = true

routing/router.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ package routing
22

33
import "net/http"
44

5-
//HandlerFunc must contain all params from the route
6-
//in the form key,value
5+
// HandlerFunc must contain all params from the route
6+
// in the form key,value
77
type HandlerFunc func(w http.ResponseWriter, r *http.Request, params map[string]string)
88

9-
//Routeable allows drop in replacement for api2go's router
10-
//by default, we are using julienschmidt/httprouter
11-
//but you can use any router that has similiar features
12-
//e.g. gin
9+
// Routeable allows drop in replacement for api2go's router
10+
// by default, we are using julienschmidt/httprouter
11+
// but you can use any router that has similiar features
12+
// e.g. gin
1313
type Routeable interface {
14-
//Handler should return the routers main handler, often this is the router itself
14+
// Handler should return the routers main handler, often this is the router itself
1515
Handler() http.Handler
16-
//Handle must be implemented to register api2go's default routines
17-
//to your used router.
18-
//protocol will be PATCH,OPTIONS,GET,POST,PUT
19-
//route will be the request route /items/:id where :id means dynamically filled params
20-
//handler is the handler that will answer to this specific route
16+
// Handle must be implemented to register api2go's default routines
17+
// to your used router.
18+
// protocol will be PATCH,OPTIONS,GET,POST,PUT
19+
// route will be the request route /items/:id where :id means dynamically filled params
20+
// handler is the handler that will answer to this specific route
2121
Handle(protocol, route string, handler HandlerFunc)
2222
}

0 commit comments

Comments
 (0)