@@ -43,7 +43,7 @@ package main
43
43
import (
44
44
" fmt"
45
45
46
- " github.com/nitrictech/go-sdk/handler "
46
+ " github.com/nitrictech/go-sdk/nitric/apis "
47
47
" github.com/nitrictech/go-sdk/nitric"
48
48
)
49
49
@@ -54,17 +54,13 @@ func main() {
54
54
return
55
55
}
56
56
57
- galaxyApi.Get (" /moon" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
57
+ galaxyApi.Get (" /moon" , func (ctx *apis. Ctx ) {
58
58
ctx.Response .Body = []byte (" that's no moon, it's a space station." )
59
-
60
- return next (ctx)
61
59
})
62
60
63
61
if err := nitric.Run (); err != nil {
64
62
fmt.Println (err)
65
63
}
66
-
67
- fmt.Println (" Service has started" )
68
64
}
69
65
```
70
66
@@ -128,7 +124,7 @@ package main
128
124
import (
129
125
" fmt"
130
126
131
- " github.com/nitrictech/go-sdk/handler "
127
+ " github.com/nitrictech/go-sdk/nitric/apis "
132
128
" github.com/nitrictech/go-sdk/nitric"
133
129
" github.com/your-org/your-repo/planets"
134
130
)
@@ -140,25 +136,19 @@ func main() {
140
136
return
141
137
}
142
138
143
- galaxyApi.Get (" /planets" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
139
+ galaxyApi.Get (" /planets" , func (ctx *apis. Ctx ) {
144
140
ctx.Response .Headers = map [string ][]string {" Content-Type" : {" application/json" }}
145
141
ctx.Response .Body = []byte (GetPlanetList ())
146
-
147
- return next (ctx)
148
142
})
149
143
150
- galaxyApi.Post (" /planets" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
144
+ galaxyApi.Post (" /planets" , func (ctx *apis. Ctx ) {
151
145
CreatePlanet (ctx.Request .Data ())
152
146
ctx.Response .Status = 201
153
-
154
- return next (ctx)
155
147
})
156
148
157
149
if err := nitric.Run (); err != nil {
158
150
fmt.Println (err)
159
151
}
160
-
161
- fmt.Println (" Service has started" )
162
152
}
163
153
164
154
```
@@ -222,7 +212,7 @@ package main
222
212
import (
223
213
" fmt"
224
214
225
- " github.com/nitrictech/go-sdk/handler "
215
+ " github.com/nitrictech/go-sdk/nitric/apis "
226
216
" github.com/nitrictech/go-sdk/nitric"
227
217
" github.com/your-org/your-repo/planets"
228
218
)
@@ -235,19 +225,15 @@ func main() {
235
225
}
236
226
237
227
// create a dynamic route and extract the parameter `name`
238
- galaxyApi.Get (" /planets/:name" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
228
+ galaxyApi.Get (" /planets/:name" , func (ctx *apis. Ctx ) {
239
229
name := ctx.Request .PathParams ()[" name" ]
240
230
241
231
ctx.Response .Body = []byte (GetPlanet (name))
242
-
243
- return next (ctx)
244
232
})
245
233
246
234
if err := nitric.Run (); err != nil {
247
235
fmt.Println (err)
248
236
}
249
-
250
- fmt.Println (" Service has started" )
251
237
}
252
238
```
253
239
@@ -290,11 +276,9 @@ async def find_alderaan(ctx):
290
276
291
277
``` go
292
278
// return a redirect response using status 301
293
- galaxyApi.Get (" /planets/alderaan" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
279
+ galaxyApi.Get (" /planets/alderaan" , func (ctx *apis. Ctx ) {
294
280
ctx.Response .Status = 301
295
281
ctx.Response .Location = " https://example.org/debris/alderaan"
296
-
297
- return next (ctx)
298
282
})
299
283
```
300
284
@@ -552,15 +536,13 @@ async def get_planet(ctx):
552
536
553
537
``` go
554
538
// override top level security to remove security from this route
555
- secureApi.Get (" /planets/unsecured-planet" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
539
+ secureApi.Get (" /planets/unsecured-planet" , func (ctx *apis. Ctx ) {
556
540
// Handle request
557
- return next (ctx)
558
541
}, nitric.WithNoMethodSecurity ())
559
542
560
543
// override top level security to require user.write scope to access
561
- secureApi.Get (" /planets/unsecured-planet" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
544
+ secureApi.Get (" /planets/unsecured-planet" , func (ctx *apis. Ctx ) {
562
545
// Handle request
563
- return next (ctx)
564
546
}, nitric.WithSecurity (customRule ([]string {" users:write" })))
565
547
```
566
548
@@ -607,7 +589,7 @@ async def validate(ctx, nxt: HttpMiddleware):
607
589
```
608
590
609
591
``` go
610
- func validate (ctx *handler . HttpContext , next handler . HttpHandler ) (*handler .HttpContext , error ) {
592
+ func validate (ctx *apis . Ctx , next nitric . Handler [ apis . Ctx ] ) (*handler .HttpContext , error ) {
611
593
if ctx.Request .Headers ()[" content-type" ] != nil {
612
594
ctx.Response .Status = 400
613
595
ctx.Response .Body = []byte (" header Content-Type is required" )
@@ -654,11 +636,11 @@ Nitric.run()
654
636
import (
655
637
" fmt"
656
638
657
- " github.com/nitrictech/go-sdk/handler "
639
+ " github.com/nitrictech/go-sdk/nitric/apis "
658
640
" github.com/nitrictech/go-sdk/nitric"
659
641
)
660
642
661
- func validate (ctx *handler . HttpContext , next handler . HttpHandler ) (*handler . HttpContext , error ) {
643
+ func validate (ctx *apis . Ctx , next nitric . Handler [ apis . Ctx ] ) (*apis . Ctx , error ) {
662
644
if ctx.Request .Headers ()[" content-type" ] != nil {
663
645
ctx.Response .Status = 400
664
646
ctx.Response .Body = []byte (" header Content-Type is required" )
@@ -719,11 +701,11 @@ Route level middleware currently not supported in python
719
701
import (
720
702
" fmt"
721
703
722
- " github.com/nitrictech/go-sdk/handler "
704
+ " github.com/nitrictech/go-sdk/nitric/apis "
723
705
" github.com/nitrictech/go-sdk/nitric"
724
706
)
725
707
726
- func validate (ctx *handler . HttpContext , next handler . HttpHandler ) (*handler . HttpContext , error ) {
708
+ func validate (ctx *apis . Ctx , next nitric . Handler [ apis . Ctx ] ) (*apis . Ctx , error ) {
727
709
if ctx.Request .Headers ()[" content-type" ] != nil {
728
710
ctx.Response .Status = 400
729
711
ctx.Response .Body = []byte (" header Content-Type is required" )
@@ -742,8 +724,8 @@ func main() {
742
724
return
743
725
}
744
726
745
- customersApi.Get (" /customers" , handler. ComposeHttpMiddleware (validate, func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
746
- return next (ctx)
727
+ customersApi.Get (" /customers" , nitric. Compose (validate, func (ctx *apis. Ctx ) {
728
+ // handle request
747
729
}))
748
730
749
731
if err := nitric.Run (); err != nil {
@@ -917,7 +899,7 @@ package main
917
899
import (
918
900
" fmt"
919
901
920
- " github.com/nitrictech/go-sdk/handler "
902
+ " github.com/nitrictech/go-sdk/nitric/apis "
921
903
" github.com/nitrictech/go-sdk/nitric"
922
904
)
923
905
@@ -928,9 +910,8 @@ func main() {
928
910
return
929
911
}
930
912
931
- accountsApi.Get (" /users/:id" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
913
+ accountsApi.Get (" /users/:id" , func (ctx *apis. Ctx ) {
932
914
// your logic here
933
- return next (ctx)
934
915
})
935
916
936
917
if err := nitric.Run (); err != nil {
@@ -983,7 +964,7 @@ package main
983
964
import (
984
965
" fmt"
985
966
986
- " github.com/nitrictech/go-sdk/handler "
967
+ " github.com/nitrictech/go-sdk/nitric/apis "
987
968
" github.com/nitrictech/go-sdk/nitric"
988
969
)
989
970
@@ -994,9 +975,8 @@ func main() {
994
975
return
995
976
}
996
977
997
- accountsApi.Get (" /orgs/:id" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
978
+ accountsApi.Get (" /orgs/:id" , func (ctx *apis. Ctx ) {
998
979
// your logic here
999
- return next (ctx)
1000
980
})
1001
981
1002
982
if err := nitric.Run (); err != nil {
@@ -1096,15 +1076,14 @@ package main
1096
1076
import (
1097
1077
" fmt"
1098
1078
1099
- " github.com/nitrictech/go-sdk/handler "
1079
+ " github.com/nitrictech/go-sdk/nitric/apis "
1100
1080
" github.com/nitrictech/go-sdk/nitric"
1101
1081
" github.com/your-org/your-repo/resources"
1102
1082
)
1103
1083
1104
1084
func main () {
1105
- Resources.AccountsApi .Get (" /users/:id" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
1085
+ Resources.AccountsApi .Get (" /users/:id" , func (ctx *apis. Ctx ) {
1106
1086
// your logic here
1107
- return next (ctx)
1108
1087
})
1109
1088
1110
1089
if err := nitric.Run (); err != nil {
@@ -1152,15 +1131,14 @@ package main
1152
1131
import (
1153
1132
" fmt"
1154
1133
1155
- " github.com/nitrictech/go-sdk/handler "
1134
+ " github.com/nitrictech/go-sdk/nitric/apis "
1156
1135
" github.com/nitrictech/go-sdk/nitric"
1157
1136
" github.com/your-org/your-repo/resources"
1158
1137
)
1159
1138
1160
1139
func main () {
1161
- Resources.AccountsApi .Get (" /orgs/:id" , func (ctx *handler. HttpContext , next handler. HttpHandler ) (*handler. HttpContext , error ) {
1140
+ Resources.AccountsApi .Get (" /orgs/:id" , func (ctx *apis. Ctx ) {
1162
1141
// your logic here
1163
- return next (ctx)
1164
1142
})
1165
1143
1166
1144
if err := nitric.Run (); err != nil {
0 commit comments