Utilities and packages containing helpful code!
List of packages:
- Path related (util)
- Serialization (util)
- GRPC Middleware (grpc/middleware)
- JWT Auth (auth/jwt)
go get -u github.com/devboxhq/go-utils
- get root path based on relative path
import "github.com/devboxhq/go-utils/pkg/util"
func main() {
path := util.FromRootPath("binaries")
}
- json to bytes
import "github.com/devboxhq/go-utils/pkg/util"
func main() {
data := util.MustJsonToBytes(jsonData)
}
- GRPC zap middleware
import (
"github.com/devboxhq/go-utils/pkg/grpc/middleware"
"go.uber.org/zap"
"google.golang.org/grpc"
)
func main() {
logger, _ := zap.NewProduction()
// create manager and add zap middleware
manager := middleware.Manager{}
_ = manager.AddMiddleware(middleware.NewZapMiddleware())
// provide middlewares to GRPC server
grpcServer := grpc.NewServer(manager.BuildServerOptions()...)
}