Skip to content

Commit dbd7326

Browse files
committed
chore(golang): generate stubs for routes
Part of #9
1 parent e4094cb commit dbd7326

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

examples/go/app.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package main
22

33
import "fmt"
4+
import "net/http"
5+
import "os"
46

57
func main() {
8+
registerRoutes()
9+
610
fmt.Println("Listen on 3000")
11+
if err := http.ListenAndServe(":3000", nil); err != nil {
12+
fmt.Fprintf(os.Stderr, "ListenAndServe failed: %v", err)
13+
os.Exit(1)
14+
}
715
}

examples/go/routes.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import "net/http"
4+
5+
func registerRoutes() {
6+
7+
http.HandleFunc("/v1/categories/count", func(w http.ResponseWriter, _ *http.Request) {
8+
w.Write([]byte("TODO"))
9+
})
10+
11+
http.HandleFunc("/v1/collections/:collectionId/categories/count", func(w http.ResponseWriter, _ *http.Request) {
12+
w.Write([]byte("TODO"))
13+
})
14+
15+
http.HandleFunc("/v1/categories", func(w http.ResponseWriter, _ *http.Request) {
16+
w.Write([]byte("TODO"))
17+
})
18+
19+
http.HandleFunc("/v1/categories/:categoryId", func(w http.ResponseWriter, _ *http.Request) {
20+
w.Write([]byte("TODO"))
21+
})
22+
23+
}

src/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ to install its dependencies and
133133
afteward to run`);
134134
} else if (argv.lang === 'go') {
135135
console.info(`Use
136-
go run app.go
136+
go run *.go
137137
or
138138
go build -o app
139139
./app
@@ -156,8 +156,8 @@ if (!fs.existsSync(destDir)) {
156156
}
157157

158158
createApp(destDir, argv.lang, config);
159+
createEndpoints(destDir, argv.lang, config);
159160
if (argv.lang === 'js') {
160-
createEndpoints(destDir, argv.lang, config);
161161
createPackageJson(destDir, 'package.json');
162162
}
163163

src/templates/app.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package main
22

33
import "fmt"
4+
import "net/http"
5+
import "os"
46

57
func main() {
8+
registerRoutes()
9+
610
fmt.Println("Listen on 3000")
11+
if err := http.ListenAndServe(":3000", nil); err != nil {
12+
fmt.Fprintf(os.Stderr, "ListenAndServe failed: %v", err)
13+
os.Exit(1)
14+
}
715
}

src/templates/routes.go.ejs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import "net/http"
4+
5+
func registerRoutes() {
6+
<% endpoints.forEach(function(endpoint) { %>
7+
http.HandleFunc("<%- endpoint.path %>", func(w http.ResponseWriter, _ *http.Request) {
8+
w.Write([]byte("TODO"))
9+
})
10+
<% }) %>
11+
}

0 commit comments

Comments
 (0)