Skip to content

Commit c51986d

Browse files
bvwellswing328
authored andcommitted
Go server clean up (#328)
1 parent 97bab92 commit c51986d

15 files changed

Lines changed: 79 additions & 58 deletions

File tree

modules/openapi-generator/src/main/resources/go-server/controller-api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
){{#operation}}
88

9+
// {{nickname}} - {{{summary}}}
910
func {{nickname}}(w http.ResponseWriter, r *http.Request) {
1011
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
1112
w.WriteHeader(http.StatusOK)

modules/openapi-generator/src/main/resources/go-server/logger.mustache

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
package {{packageName}}
33

44
import (
5-
"log"
6-
"net/http"
7-
"time"
5+
"log"
6+
"net/http"
7+
"time"
88
)
99

1010
func Logger(inner http.Handler, name string) http.Handler {
11-
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12-
start := time.Now()
11+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12+
start := time.Now()
1313
14-
inner.ServeHTTP(w, r)
14+
inner.ServeHTTP(w, r)
1515
16-
log.Printf(
17-
"%s %s %s %s",
18-
r.Method,
19-
r.RequestURI,
20-
name,
21-
time.Since(start),
22-
)
23-
})
16+
log.Printf(
17+
"%s %s %s %s",
18+
r.Method,
19+
r.RequestURI,
20+
name,
21+
time.Since(start),
22+
)
23+
})
2424
}

modules/openapi-generator/src/main/resources/go-server/model.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
{{/enumVars}}
1616
{{/allowableValues}}
1717
){{/isEnum}}{{^isEnum}}{{#description}}
18-
// {{{description}}}{{/description}}
18+
// {{classname}} - {{{description}}}{{/description}}
1919
type {{classname}} struct {
2020
{{#vars}}{{#description}}
2121
// {{{description}}}{{/description}}

modules/openapi-generator/src/main/resources/go-server/routers.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ func Index(w http.ResponseWriter, r *http.Request) {
4040
}
4141

4242
var routes = Routes{
43-
Route{
43+
{
4444
"Index",
4545
"GET",
4646
"{{{basePathWithoutHost}}}/",
4747
Index,
4848
},{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
4949

50-
Route{
50+
{
5151
"{{operationId}}",
5252
strings.ToUpper("{{httpMethod}}"),
5353
"{{{basePathWithoutHost}}}{{{path}}}",

samples/server/petstore/go-api-server/go/api_pet.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,49 @@ import (
1313
"net/http"
1414
)
1515

16+
// AddPet - Add a new pet to the store
1617
func AddPet(w http.ResponseWriter, r *http.Request) {
1718
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
1819
w.WriteHeader(http.StatusOK)
1920
}
2021

22+
// DeletePet - Deletes a pet
2123
func DeletePet(w http.ResponseWriter, r *http.Request) {
2224
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
2325
w.WriteHeader(http.StatusOK)
2426
}
2527

28+
// FindPetsByStatus - Finds Pets by status
2629
func FindPetsByStatus(w http.ResponseWriter, r *http.Request) {
2730
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
2831
w.WriteHeader(http.StatusOK)
2932
}
3033

34+
// FindPetsByTags - Finds Pets by tags
3135
func FindPetsByTags(w http.ResponseWriter, r *http.Request) {
3236
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
3337
w.WriteHeader(http.StatusOK)
3438
}
3539

40+
// GetPetById - Find pet by ID
3641
func GetPetById(w http.ResponseWriter, r *http.Request) {
3742
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
3843
w.WriteHeader(http.StatusOK)
3944
}
4045

46+
// UpdatePet - Update an existing pet
4147
func UpdatePet(w http.ResponseWriter, r *http.Request) {
4248
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
4349
w.WriteHeader(http.StatusOK)
4450
}
4551

52+
// UpdatePetWithForm - Updates a pet in the store with form data
4653
func UpdatePetWithForm(w http.ResponseWriter, r *http.Request) {
4754
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
4855
w.WriteHeader(http.StatusOK)
4956
}
5057

58+
// UploadFile - uploads an image
5159
func UploadFile(w http.ResponseWriter, r *http.Request) {
5260
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
5361
w.WriteHeader(http.StatusOK)

samples/server/petstore/go-api-server/go/api_store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@ import (
1313
"net/http"
1414
)
1515

16+
// DeleteOrder - Delete purchase order by ID
1617
func DeleteOrder(w http.ResponseWriter, r *http.Request) {
1718
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
1819
w.WriteHeader(http.StatusOK)
1920
}
2021

22+
// GetInventory - Returns pet inventories by status
2123
func GetInventory(w http.ResponseWriter, r *http.Request) {
2224
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
2325
w.WriteHeader(http.StatusOK)
2426
}
2527

28+
// GetOrderById - Find purchase order by ID
2629
func GetOrderById(w http.ResponseWriter, r *http.Request) {
2730
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
2831
w.WriteHeader(http.StatusOK)
2932
}
3033

34+
// PlaceOrder - Place an order for a pet
3135
func PlaceOrder(w http.ResponseWriter, r *http.Request) {
3236
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
3337
w.WriteHeader(http.StatusOK)

samples/server/petstore/go-api-server/go/api_user.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,49 @@ import (
1313
"net/http"
1414
)
1515

16+
// CreateUser - Create user
1617
func CreateUser(w http.ResponseWriter, r *http.Request) {
1718
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
1819
w.WriteHeader(http.StatusOK)
1920
}
2021

22+
// CreateUsersWithArrayInput - Creates list of users with given input array
2123
func CreateUsersWithArrayInput(w http.ResponseWriter, r *http.Request) {
2224
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
2325
w.WriteHeader(http.StatusOK)
2426
}
2527

28+
// CreateUsersWithListInput - Creates list of users with given input array
2629
func CreateUsersWithListInput(w http.ResponseWriter, r *http.Request) {
2730
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
2831
w.WriteHeader(http.StatusOK)
2932
}
3033

34+
// DeleteUser - Delete user
3135
func DeleteUser(w http.ResponseWriter, r *http.Request) {
3236
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
3337
w.WriteHeader(http.StatusOK)
3438
}
3539

40+
// GetUserByName - Get user by user name
3641
func GetUserByName(w http.ResponseWriter, r *http.Request) {
3742
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
3843
w.WriteHeader(http.StatusOK)
3944
}
4045

46+
// LoginUser - Logs user into the system
4147
func LoginUser(w http.ResponseWriter, r *http.Request) {
4248
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
4349
w.WriteHeader(http.StatusOK)
4450
}
4551

52+
// LogoutUser - Logs out current logged in user session
4653
func LogoutUser(w http.ResponseWriter, r *http.Request) {
4754
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
4855
w.WriteHeader(http.StatusOK)
4956
}
5057

58+
// UpdateUser - Updated user
5159
func UpdateUser(w http.ResponseWriter, r *http.Request) {
5260
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
5361
w.WriteHeader(http.StatusOK)

samples/server/petstore/go-api-server/go/logger.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
package petstoreserver
1111

1212
import (
13-
"log"
14-
"net/http"
15-
"time"
13+
"log"
14+
"net/http"
15+
"time"
1616
)
1717

1818
func Logger(inner http.Handler, name string) http.Handler {
19-
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20-
start := time.Now()
19+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20+
start := time.Now()
2121

22-
inner.ServeHTTP(w, r)
22+
inner.ServeHTTP(w, r)
2323

24-
log.Printf(
25-
"%s %s %s %s",
26-
r.Method,
27-
r.RequestURI,
28-
name,
29-
time.Since(start),
30-
)
31-
})
24+
log.Printf(
25+
"%s %s %s %s",
26+
r.Method,
27+
r.RequestURI,
28+
name,
29+
time.Since(start),
30+
)
31+
})
3232
}

samples/server/petstore/go-api-server/go/model_api_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package petstoreserver
1111

12-
// Describes the result of uploading an image resource
12+
// ApiResponse - Describes the result of uploading an image resource
1313
type ApiResponse struct {
1414

1515
Code int32 `json:"code,omitempty"`

samples/server/petstore/go-api-server/go/model_category.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package petstoreserver
1111

12-
// A category for a pet
12+
// Category - A category for a pet
1313
type Category struct {
1414

1515
Id int64 `json:"id,omitempty"`

0 commit comments

Comments
 (0)