Skip to content

Commit

Permalink
chore: appease the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard committed Dec 22, 2024
1 parent 8835686 commit c1388c7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/minecraft-preempt-agent/minecraft-preempt-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var rootCmd = &cobra.Command{
}

// entrypoint is the entrypoint for the root command
func entrypoint(cCmd *cobra.Command, args []string) error {
func entrypoint(cCmd *cobra.Command, _ []string) error {
ctx, cancel := context.WithCancel(cCmd.Context())
defer cancel()

Expand Down
8 changes: 5 additions & 3 deletions cmd/minecraft-preempt/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main
import (
"context"
"fmt"
"strconv"
"strings"

mcnet "github.com/Tnze/go-mc/net"
Expand Down Expand Up @@ -67,7 +66,10 @@ type ConnectionHooks struct {

// NewConnection creates a new connection to the provided server. The
// provided handshake is replayed to the server.
func NewConnection(mc *minecraft.Client, log *log.Logger, s *Server, h *minecraft.Handshake, hooks *ConnectionHooks) *Connection {
//
//nolint:gocritic // Why: OK shadowing log.
func NewConnection(mc *minecraft.Client, log *log.Logger, s *Server,
h *minecraft.Handshake, hooks *ConnectionHooks) *Connection {
return &Connection{mc, log, s, h, hooks}
}

Expand Down Expand Up @@ -235,7 +237,7 @@ func (c *Connection) Proxy(ctx context.Context) error {

sconf := c.s.config.Minecraft
c.log.Info("Proxying connection", "host", sconf.Hostname, "port", sconf.Port)
rconn, err := mcnet.DialMC(sconf.Hostname + ":" + strconv.Itoa(int(sconf.Port)))
rconn, err := mcnet.DialMC(fmt.Sprintf("%s:%d", sconf.Hostname, sconf.Port))
if err != nil {
return errors.Wrap(err, "failed to connect to remote")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/minecraft-preempt/minecraft-preempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ var rootCmd = &cobra.Command{
}

// entrypoint is the entrypoint for the root command
func entrypoint(cmd *cobra.Command, args []string) {
func entrypoint(cmd *cobra.Command, _ []string) {
ctx := cmd.Context()

//nolint:gocritic // Why: OK shadowing log.
log := log.NewWithOptions(os.Stderr, log.Options{
ReportCaller: true,
ReportTimestamp: true,
Expand Down
4 changes: 4 additions & 0 deletions cmd/minecraft-preempt/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Proxy struct {
}

// NewProxy creates a new proxy
//
//nolint:gocritic // Why: OK shadowing log.
func NewProxy(log *log.Logger, listenAddress string, s []*Server) *Proxy {
servers := make(map[string]*Server)
for _, server := range s {
Expand All @@ -70,6 +72,7 @@ func (p *Proxy) watcher(ctx context.Context) error {
// for each server, check the status. Shutdown if we're empty longer
// than our configured time.
for serverAddress, server := range p.servers {
//nolint:gocritic // Why: OK shadowing log.
log := p.log.With("server", serverAddress)
// if we have connections, don't try to stop the server
if server.connections.Load() != 0 {
Expand Down Expand Up @@ -170,6 +173,7 @@ func (p *Proxy) handleConnection(ctx context.Context, rawConn *mcnet.Conn) error
Conn: rawConn,
}

//nolint:gocritic // Why: OK shadowing log.
log := p.log.With("client", rawConn.Socket.RemoteAddr())
h, err := minecraftConn.Handshake()
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions cmd/minecraft-preempt/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@ func GetCloudProviderForConfig(conf *config.ServerConfig) (cloud.Provider, strin
return nil, "", fmt.Errorf("cannot specify both GCP and Docker")
}

if conf.GCP != nil {
switch {
case conf.GCP != nil:
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

cloudProvider, err = gcp.NewClient(ctx, conf.GCP.Project, conf.GCP.Zone)
instanceID = conf.GCP.InstanceID
} else if conf.Docker != nil {
case conf.Docker != nil:
cloudProvider, err = docker.NewClient()
instanceID = conf.Docker.ContainerID
} else {
default:
err = fmt.Errorf("no cloud provider specified")
}

return cloudProvider, instanceID, err
}

// NewServer creates a new server
//
//nolint:gocritic // Why: OK shadowing log.
func NewServer(log *log.Logger, conf *config.ServerConfig) (*Server, error) {
cloudProvider, instanceID, err := GetCloudProviderForConfig(conf)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cloud/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Client) Stop(ctx context.Context, containerID string) error {
}

// ShouldTerminate returns true if the instance should be terminated.
func (c *Client) ShouldTerminate(ctx context.Context) (bool, error) {
func (c *Client) ShouldTerminate(_ context.Context) (bool, error) {
// Here for tests, if `shutdown.txt` exists, shutdown.
if _, err := os.Stat("shutdown.txt"); err == nil {
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/minecraft/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package minecraft

import (
"encoding/json"
"strconv"
"fmt"
"time"

"github.com/Tnze/go-mc/bot"
Expand Down Expand Up @@ -54,7 +54,7 @@ func ListenMC(addr string) (*mcnet.Listener, error) {

// GetServerStatus returns a server's status
func GetServerStatus(addr string, port uint) (*Status, error) {
b, _, err := bot.PingAndListTimeout(addr+":"+strconv.Itoa(int(port)), time.Second*30)
b, _, err := bot.PingAndListTimeout(fmt.Sprintf("%s:%d", addr, port), time.Second*30)
if err != nil {
return nil, errors.Wrap(err, "failed to ping server")
}
Expand Down
6 changes: 0 additions & 6 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@ package version

// Version is the version of the program.
var Version = "unset"

func init() {
if Version == "unset" {
panic("Version is unset, please run `make`")
}
}

0 comments on commit c1388c7

Please sign in to comment.