This repository has been archived by the owner on Jan 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactionmap.go
75 lines (64 loc) · 2.21 KB
/
actionmap.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Digivance MVC Application Framework
Action Map Features
Dan Mayor (dmayor@digivance.com)
This file defines functionality for mapping an action method to an http request optionally
boud to an http verb.
*/
package mvcapp
// ActionMethod defines the method signature for controller action methods
type ActionMethod func([]string) *ActionResult
// ActionMap is used to define the HTTP Verb, Controller's Action Name
// and the corresponding action method
type ActionMap struct {
// Verb is the HTTP Verb to bind this mapping to, blank to respond to all
Verb string
// Name is the site.com/controller/<ACTION> name that this map handles
Name string
// Method is the actual action method to execute on the controller
Method ActionMethod
}
// NewActionMap returns a new ActionMap struct populated with the given parameters
func NewActionMap(httpVerb string, actionName string, actionMethod ActionMethod) *ActionMap {
return &ActionMap{
Verb: httpVerb,
Name: actionName,
Method: actionMethod,
}
}
// NewGetActionMap returns a new ActionMap struct populated with the given parameters
// and sets the HTTP Verb to get
func NewGetActionMap(actionName string, actionMethod ActionMethod) *ActionMap {
return &ActionMap{
Verb: "GET",
Name: actionName,
Method: actionMethod,
}
}
// NewPostActionMap returns a new ActionMap struct populated with the given parameters
// and sets the HTTP Verb to post
func NewPostActionMap(actionName string, actionMethod ActionMethod) *ActionMap {
return &ActionMap{
Verb: "POST",
Name: actionName,
Method: actionMethod,
}
}
// NewPutActionMap returns a new ActionMap struct populated with the given parameters
// and sets the HTTP Verb to put
func NewPutActionMap(actionName string, actionMethod ActionMethod) *ActionMap {
return &ActionMap{
Verb: "PUT",
Name: actionName,
Method: actionMethod,
}
}
// NewDeleteActionMap returns a new ActionMap struct populated with the given parameters
// and sets the HTTP Verb to delete
func NewDeleteActionMap(actionName string, actionMethod ActionMethod) *ActionMap {
return &ActionMap{
Verb: "DELETE",
Name: actionName,
Method: actionMethod,
}
}