8000 feat(grpc): use const for codes by alexfalkowski · Pull Request #1724 · alexfalkowski/go-service · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(grpc): use const for codes #1724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions debug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewServer(params ServerParams) (*Server, error) {
timeout := time.MustParseDuration(params.Config.Timeout)
svr := http.NewServer(timeout, params.Mux)

cfg, err := conf(params.FS, params.Config)
cfg, err := newConfig(params.FS, params.Config)
if err != nil {
return nil, prefix(err)
}
Expand All @@ -62,7 +62,7 @@ func (s *Server) GetService() *server.Service {
return s.Service
}

func conf(fs *os.FS, cfg *Config) (*config.Config, error) {
func newConfig(fs *os.FS, cfg *Config) (*config.Config, error) {
config := &config.Config{
Address: cmp.Or(cfg.Address, ":6060"),
}
Expand Down
2 changes: 1 addition & 1 deletion net/grpc/codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "google.golang.org/grpc/codes"
// Code is an alias for codes.Code.
type Code = codes.Code

var (
const (
// Aborted is an alias for codes.Aborted.
Aborted = codes.Aborted

Expand Down
12 changes: 12 additions & 0 deletions net/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const (
// StatusBadRequest is an alias of http.StatusBadRequest.
StatusBadRequest = http.StatusBadRequest

// StatusConflict is an alias of http.StatusConflict.
StatusConflict = http.StatusConflict

// StatusForbidden is an alias of http.StatusForbidden.
StatusForbidden = http.StatusForbidden

// StatusGatewayTimeout is an alias of http.StatusGatewayTimeout.
StatusGatewayTimeout = http.StatusGatewayTimeout

// StatusOK is an alias of http.StatusOK.
StatusOK = http.StatusOK

Expand All @@ -37,6 +46,9 @@ const (
// StatusNotFound is an alias of http.StatusNotFound.
StatusNotFound = http.StatusNotFound

// StatusNotImplemented is an alias of http.StatusNotImplemented.
StatusNotImplemented = http.StatusNotImplemented

// StatusServiceUnavailable is an alias of http.StatusServiceUnavailable.
StatusServiceUnavailable = http.StatusServiceUnavailable

Expand Down
3 changes: 1 addition & 2 deletions net/http/status/codes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package status

import (
"net/http"

"github.com/alexfalkowski/go-service/v2/net/grpc/codes"
"github.com/alexfalkowski/go-service/v2/net/http"
)

// Taken from https://github.com/grpc-ecosystem/grpc-gateway/blob/main/runtime/errors.go
Expand Down
4 changes: 2 additions & 2 deletions transport/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewServer(params ServerParams) (*Server, error) {
return nil, nil
}

opt, err := creds(params.FS, params.Config)
opt, err := credsServerOption(params.FS, params.Config)
if err != nil {
return nil, prefix(err)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func streamServerOption(params ServerParams, server *metrics.Server, interceptor
return grpc.ChainStreamInterceptor(sis...)
}

func creds(fs *os.FS, cfg *Config) (grpc.ServerOption, error) {
func credsServerOption(fs *os.FS, cfg *Config) (grpc.ServerOption, error) {
if !tls.IsEnabled(cfg.TLS) {
return grpc.EmptyServerOption{}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions transport/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewServer(params ServerParams) (*Server, error) {
timeout := time.MustParseDuration(params.Config.Timeout)
svr := http.NewServer(timeout, neg)

cfg, err := conf(params.FS, params.Config)
cfg, err := newConfig(params.FS, params.Config)
if err != nil {
return nil, prefix(err)
}
Expand All @@ -108,7 +108,7 @@ func (s *Server) GetService() *server.Service {
return s.Service
}

func conf(fs *os.FS, cfg *Config) (*config.Config, error) {
func newConfig(fs *os.FS, cfg *Config) (*config.Config, error) {
config := &config.Config{
Address: cmp.Or(cfg.Address, ":8080"),
}
Expand Down
0