diff --git a/Makefile b/Makefile index eb2fd6f..125225b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,10 @@ build: rm -rf pokedex* swag init protoc -I=./ --go_out=../ ./pokemon/pokemon.proto - go build - + go build pokedex +optimize: + go build -ldflags "-s -w" pokedex + upx pokedex +prod: build optimize diff --git a/README.md b/README.md index 035769f..c31d3bc 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,19 @@ A simple Go-powered REST API kata. ## Protobuf +Why? Separation of concerns; do not expose database/domain internals. Structs in `pokemon.go` should not leave the package. The `.proto` file serve as the official "contracts". + - JSON mapping: https://protobuf.dev/programming-guides/proto3/#json +- `Pokemons` as object with `entries` is ugly but see https://github.com/golang/protobuf/issues/675 - no way to convert a slice to a protobuf message... ## Swagger - Exposed at `http://localhost:8080/docs` - Regenerate with `swag init`, see https://github.com/swaggo/http-swagger -- Annotation format: see https://github.com/swaggo/swag \ No newline at end of file +- Annotation format: see https://github.com/swaggo/swag + +## Optimizing the binary + +See `Makefile`; use https://upx.github.io/ to package after stripping some debug info. + +Somehow doesn't work on OSX (process killed)? \ No newline at end of file diff --git a/main.go b/main.go index 0b1fad4..3f7b8b7 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/swaggo/http-swagger" "gorm.io/driver/sqlite" "gorm.io/gorm" @@ -40,5 +41,6 @@ func main() { http.HandleFunc("GET /docs/", httpSwagger.Handler( httpSwagger.URL("http://localhost:8080/docs/doc.json"), //The url pointing to API definition )) + fmt.Println("Pokedex server started @ http://localhost:8080") http.ListenAndServe(":8080", nil) }