You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cmd/momentum-cli/readme.md
+69-2Lines changed: 69 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Generate RPC functions and Javascript libraries with your Go Code.
10
10
11
11
go get github.com/cheikhshift/momentum/cmd/momentum-cli
12
12
13
-
## Example
13
+
## Example 1
14
14
The following function will be parsed by momentum-cli :
15
15
16
16
// RPC
@@ -25,6 +25,52 @@ The previous func will generate JS function : (The variable definitions carry o
25
25
26
26
Notes : Within callback function parameter `ObjectResponse` (javascript type object) the object key `result` will have your function's result, following the named variables provided. Callback function parameter `success` (javascript type boolean) is optional and indicates a successful HTTP request to the server. If `success` is false, `ObjectResponse` will have one object key, which will be `error`. `error` is a string message of why the request has failed.
27
27
28
+
## Example 2
29
+
An interface function will be used with this example. The following function will be parsed by momentum-cli :
30
+
31
+
type Stk struct {
32
+
Var string
33
+
}
34
+
35
+
// RPC
36
+
func (st * Stk) TestFunction () (res string) {
37
+
log.Println("hello")
38
+
log.Println(st.Var)
39
+
st.Var = "Newval"
40
+
res = "value string"
41
+
return
42
+
}
43
+
44
+
The previous func will generate the following JS code : (The interface initializer will be available in JS)
Momentum will generate an additional go file. This file will have the same package name as its neighbors (go files in directory you ran command).
30
76
@@ -71,6 +117,19 @@ Use this function to chain multiple generated Momentum javascript libraries.
71
117
return
72
118
}
73
119
120
+
type Stk struct {
121
+
Var string
122
+
}
123
+
124
+
// RPC
125
+
func (st * Stk) TestFunction () (res string) {
126
+
log.Println("hello")
127
+
log.Println(st.Var)
128
+
st.Var = "Newval"
129
+
res = "value string"
130
+
return
131
+
}
132
+
74
133
75
134
func main(){
76
135
r := mux.NewRouter()
@@ -94,4 +153,12 @@ name : specifies the name of the function to invoke.
94
153
95
154
## Post Body
96
155
97
-
The body is used to pass a json of your function's variables/parameters. Each json key should match a correponding function parameter name, with that parameter's data specified as the key's value. Even if your function has no parameters, pass atleast pass an empty JSON. If no data is passed momentum will return an EOF JSON error.
156
+
The body is used to pass a JSON of your function's variables/parameters. Each JSON key should match a corresponding function parameter name, with that parameter's data specified as the key's value. Even if your function has no parameters, pass at least an empty JSON (`{}`). If no data is passed momentum will return an EOF JSON error.
157
+
158
+
### Response format
159
+
With interface methods the response format differs. Here is the schema
160
+
161
+
{
162
+
"Obj" : {} ,// interface with updates from function
163
+
"Result" : {} , // result of function. Null if function returns nothing.
0 commit comments