try to optimize the binary using UPX

This commit is contained in:
Wouter Groeneveld 2024-04-15 14:09:29 +02:00
parent fd10dbbd13
commit 3237dcbc2a
3 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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
- 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)?

View File

@ -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)
}