Skip to content

Commit

Permalink
Minor refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Nov 23, 2024
1 parent 7f0d33d commit ce750b5
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 71 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/heroiclabs/nakama-common v1.34.1-0.20241121105602-e24311ad3419
github.com/heroiclabs/nakama-common v1.34.1-0.20241123094823-fd6420e8b69d
github.com/heroiclabs/sql-migrate v0.0.0-20240528102547-233afc8cf05a
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
github.com/jackc/pgx/v5 v5.6.0
Expand Down Expand Up @@ -74,5 +74,3 @@ require (
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
)

replace github.com/heroiclabs/nakama-common => ../nakama-common
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZH
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/heroiclabs/nakama-common v1.34.1-0.20241123094823-fd6420e8b69d h1:Ovj8fbsxDXldEDXwwlYtCtWgSSEZtgy/S4ou2Mprdfk=
github.com/heroiclabs/nakama-common v1.34.1-0.20241123094823-fd6420e8b69d/go.mod h1:lPG64MVCs0/tEkh311Cd6oHX9NLx2vAPx7WW7QCJHQ0=
github.com/heroiclabs/sql-migrate v0.0.0-20240528102547-233afc8cf05a h1:tuL2ZPaeCbNw8rXmV9ywd00nXRv95V4/FmbIGKLQJAE=
github.com/heroiclabs/sql-migrate v0.0.0-20240528102547-233afc8cf05a/go.mod h1:hzCTPoEi/oml2BllVydJcNP63S7b56e5DzeQeLGvw1U=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
62 changes: 31 additions & 31 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,17 +641,17 @@ func (c *config) GetRuntimeConfig() (runtime.Config, error) {
var gauth runtime.GoogleAuthConfig = clone.GetGoogleAuth()
var satori runtime.SatoriConfig = clone.GetSatori()

cn := runtimeConfig{
name: clone.GetName(),
shutdownGrace: clone.GetShutdownGraceSec(),
logger: lc,
session: sc,
socket: soc,
social: socialConf,
runtime: rc,
iap: iap,
googleAuth: gauth,
satori: satori,
cn := &RuntimeConfigClone{
Name: clone.GetName(),
ShutdownGrace: clone.GetShutdownGraceSec(),
Logger: lc,
Session: sc,
Socket: soc,
Social: socialConf,
Runtime: rc,
Iap: iap,
GoogleAuth: gauth,
Satori: satori,
}

return cn, nil
Expand All @@ -678,7 +678,7 @@ type LoggerConfig struct {
Format string `yaml:"format" json:"format" usage:"Set logging output format. Can either be 'JSON' or 'Stackdriver'. Default is 'JSON'."`
}

func (cfg LoggerConfig) GetLevel() string {
func (cfg *LoggerConfig) GetLevel() string {
return cfg.Level
}

Expand Down Expand Up @@ -827,19 +827,19 @@ type SocketConfig struct {
TLSCert []tls.Certificate `yaml:"-" json:"-"` // Created by processing CertPEMBlock and KeyPEMBlock, not set from input args directly.
}

func (cfg SocketConfig) GetServerKey() string {
func (cfg *SocketConfig) GetServerKey() string {
return cfg.ServerKey
}

func (cfg SocketConfig) GetPort() int {
func (cfg *SocketConfig) GetPort() int {
return cfg.Port
}

func (cfg SocketConfig) GetAddress() string {
func (cfg *SocketConfig) GetAddress() string {
return cfg.Address
}

func (cfg SocketConfig) GetProtocol() string {
func (cfg *SocketConfig) GetProtocol() string {
return cfg.Protocol
}

Expand Down Expand Up @@ -946,19 +946,19 @@ type SocialConfig struct {
Apple *SocialConfigApple `yaml:"apple" json:"apple" usage:"Apple Sign In configuration."`
}

func (cfg SocialConfig) GetSteam() runtime.SocialConfigSteam {
func (cfg *SocialConfig) GetSteam() runtime.SocialConfigSteam {
return cfg.Steam
}

func (cfg SocialConfig) GetFacebookInstantGame() runtime.SocialConfigFacebookInstantGame {
func (cfg *SocialConfig) GetFacebookInstantGame() runtime.SocialConfigFacebookInstantGame {
return cfg.FacebookInstantGame
}

func (cfg SocialConfig) GetFacebookLimitedLogin() runtime.SocialConfigFacebookLimitedLogin {
func (cfg *SocialConfig) GetFacebookLimitedLogin() runtime.SocialConfigFacebookLimitedLogin {
return cfg.FacebookLimitedLogin
}

func (cfg SocialConfig) GetApple() runtime.SocialConfigApple {
func (cfg *SocialConfig) GetApple() runtime.SocialConfigApple {
return cfg.Apple
}

Expand Down Expand Up @@ -1340,19 +1340,19 @@ type IAPConfig struct {
FacebookInstant *IAPFacebookInstantConfig `yaml:"facebook_instant" json:"facebook_instant" usage:"Facebook Instant purchase validation configuration."`
}

func (cfg IAPConfig) GetApple() runtime.IAPAppleConfig {
func (cfg *IAPConfig) GetApple() runtime.IAPAppleConfig {
return cfg.Apple
}

func (cfg IAPConfig) GetGoogle() runtime.IAPGoogleConfig {
func (cfg *IAPConfig) GetGoogle() runtime.IAPGoogleConfig {
return cfg.Google
}

func (cfg IAPConfig) GetHuawei() runtime.IAPHuaweiConfig {
func (cfg *IAPConfig) GetHuawei() runtime.IAPHuaweiConfig {
return cfg.Huawei
}

func (cfg IAPConfig) GetFacebookInstant() runtime.IAPFacebookInstantConfig {
func (cfg *IAPConfig) GetFacebookInstant() runtime.IAPFacebookInstantConfig {
return cfg.FacebookInstant
}

Expand Down Expand Up @@ -1417,23 +1417,23 @@ type IAPGoogleConfig struct {
PackageName string `yaml:"package_name" json:"package_name" usage:"Google Play Store App Package Name."`
}

func (iapg IAPGoogleConfig) GetClientEmail() string {
func (iapg *IAPGoogleConfig) GetClientEmail() string {
return iapg.ClientEmail
}

func (iapg IAPGoogleConfig) GetPrivateKey() string {
func (iapg *IAPGoogleConfig) GetPrivateKey() string {
return iapg.PrivateKey
}

func (iapg IAPGoogleConfig) GetNotificationsEndpointId() string {
func (iapg *IAPGoogleConfig) GetNotificationsEndpointId() string {
return iapg.NotificationsEndpointId
}

func (iapg IAPGoogleConfig) GetRefundCheckPeriodMin() int {
func (iapg *IAPGoogleConfig) GetRefundCheckPeriodMin() int {
return iapg.RefundCheckPeriodMin
}

func (iapg IAPGoogleConfig) GetPackageName() string {
func (iapg *IAPGoogleConfig) GetPackageName() string {
return iapg.PackageName
}

Expand All @@ -1453,7 +1453,7 @@ type SatoriConfig struct {
SigningKey string `yaml:"signing_key" json:"signing_key" usage:"Key used to sign Satori session tokens."`
}

func (sc SatoriConfig) GetUrl() string {
func (sc *SatoriConfig) GetUrl() string {
return sc.Url
}

Expand Down Expand Up @@ -1540,7 +1540,7 @@ type GoogleAuthConfig struct {
OAuthConfig *oauth2.Config `yaml:"-" json:"-"`
}

func (cfg GoogleAuthConfig) GetCredentialsJSON() string {
func (cfg *GoogleAuthConfig) GetCredentialsJSON() string {
return cfg.CredentialsJSON
}

Expand Down
9 changes: 5 additions & 4 deletions server/console_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package server

import (
"context"
"errors"
"strings"

"github.com/gofrs/uuid/v5"
Expand All @@ -28,7 +29,7 @@ import (

func (s *ConsoleServer) ListMatches(ctx context.Context, in *console.ListMatchesRequest) (*console.MatchList, error) {
matchID := in.MatchId
// Try get match ID for authoritative query
// Try to get match ID for authoritative query.
if in.Authoritative != nil && in.Authoritative.Value && in.Query != nil {
matchID = in.Query.Value
}
Expand All @@ -40,7 +41,7 @@ func (s *ConsoleServer) ListMatches(ctx context.Context, in *console.ListMatches
}
return &console.MatchList{Matches: []*console.MatchList_Match{{ApiMatch: match, Node: node}}}, nil
} else {
if err == runtime.ErrMatchIdInvalid {
if errors.Is(err, runtime.ErrMatchIdInvalid) {
if (in.Authoritative != nil && !in.Authoritative.Value) || in.Authoritative == nil {
return nil, status.Error(codes.InvalidArgument, "Match ID is not valid.")
}
Expand Down Expand Up @@ -111,10 +112,10 @@ func (s *ConsoleServer) GetMatchState(ctx context.Context, in *console.MatchStat

presences, tick, state, err := s.matchRegistry.GetState(ctx, matchID, node)
if err != nil {
if err != context.Canceled && err != runtime.ErrMatchNotFound {
if !errors.Is(err, context.Canceled) && !errors.Is(err, runtime.ErrMatchNotFound) {
s.logger.Error("Error getting match state.", zap.Any("in", in), zap.Error(err))
}
if err == runtime.ErrMatchNotFound {
if errors.Is(err, runtime.ErrMatchNotFound) {
return nil, status.Error(codes.InvalidArgument, "Match not found, or match handler already stopped.")
}
return nil, status.Error(codes.Internal, "Error listing matches.")
Expand Down
85 changes: 54 additions & 31 deletions server/runtime_config.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@
// Copyright 2024 The Nakama Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package server

import "github.com/heroiclabs/nakama-common/runtime"

type runtimeConfig struct {
name string
shutdownGrace int
logger runtime.LoggerConfig
session runtime.SessionConfig
socket runtime.SocketConfig
social runtime.SocialConfig
runtime runtime.RuntimeConfig
iap runtime.IAPConfig
googleAuth runtime.GoogleAuthConfig
satori runtime.SatoriConfig
type RuntimeConfigClone struct {
Name string
ShutdownGrace int
Logger runtime.LoggerConfig
Session runtime.SessionConfig
Socket runtime.SocketConfig
Social runtime.SocialConfig
Runtime runtime.RuntimeConfig
Iap runtime.IAPConfig
GoogleAuth runtime.GoogleAuthConfig
Satori runtime.SatoriConfig
}

func (c runtimeConfig) GetName() string {
return c.name
func (c *RuntimeConfigClone) GetName() string {
return c.Name
}
func (c runtimeConfig) GetShutdownGraceSec() int {
return c.shutdownGrace

func (c *RuntimeConfigClone) GetShutdownGraceSec() int {
return c.ShutdownGrace
}
func (c runtimeConfig) GetLogger() runtime.LoggerConfig {
return c.logger

func (c *RuntimeConfigClone) GetLogger() runtime.LoggerConfig {
return c.Logger
}
func (c runtimeConfig) GetSession() runtime.SessionConfig {
return c.session

func (c *RuntimeConfigClone) GetSession() runtime.SessionConfig {
return c.Session
}
func (c runtimeConfig) GetSocket() runtime.SocketConfig {
return c.socket

func (c *RuntimeConfigClone) GetSocket() runtime.SocketConfig {
return c.Socket
}
func (c runtimeConfig) GetSocial() runtime.SocialConfig {
return c.social

func (c *RuntimeConfigClone) GetSocial() runtime.SocialConfig {
return c.Social
}
func (c runtimeConfig) GetRuntime() runtime.RuntimeConfig {
return c.runtime

func (c *RuntimeConfigClone) GetRuntime() runtime.RuntimeConfig {
return c.Runtime
}
func (c runtimeConfig) GetIAP() runtime.IAPConfig {
return c.iap

func (c *RuntimeConfigClone) GetIAP() runtime.IAPConfig {
return c.Iap
}
func (c runtimeConfig) GetGoogleAuth() runtime.GoogleAuthConfig {
return c.googleAuth

func (c *RuntimeConfigClone) GetGoogleAuth() runtime.GoogleAuthConfig {
return c.GoogleAuth
}
func (c runtimeConfig) GetSatori() runtime.SatoriConfig {
return c.satori

func (c *RuntimeConfigClone) GetSatori() runtime.SatoriConfig {
return c.Satori
}
3 changes: 1 addition & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopena
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options
github.com/grpc-ecosystem/grpc-gateway/v2/runtime
github.com/grpc-ecosystem/grpc-gateway/v2/utilities
# github.com/heroiclabs/nakama-common v1.34.1-0.20241121105602-e24311ad3419 => ../nakama-common
# github.com/heroiclabs/nakama-common v1.34.1-0.20241123094823-fd6420e8b69d
## explicit; go 1.19
github.com/heroiclabs/nakama-common/api
github.com/heroiclabs/nakama-common/rtapi
Expand Down Expand Up @@ -417,4 +417,3 @@ gopkg.in/natefinch/lumberjack.v2
# gopkg.in/yaml.v3 v3.0.1
## explicit
gopkg.in/yaml.v3
# github.com/heroiclabs/nakama-common => ../nakama-common

0 comments on commit ce750b5

Please sign in to comment.