2023-03-19 21:42:21 +00:00
|
|
|
// Copyright 2023 Woodpecker Authors
|
2018-02-19 22:24:10 +00:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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.
|
|
|
|
|
2024-02-08 15:33:22 +00:00
|
|
|
package core
|
2016-04-20 01:37:53 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-16 10:14:02 +00:00
|
|
|
"context"
|
2020-05-16 18:56:24 +00:00
|
|
|
"crypto/tls"
|
2023-03-19 21:42:21 +00:00
|
|
|
"errors"
|
2023-04-28 18:41:05 +00:00
|
|
|
"fmt"
|
2024-10-06 15:13:41 +00:00
|
|
|
"maps"
|
2017-09-12 18:25:55 +00:00
|
|
|
"net/http"
|
2017-07-19 21:46:03 +00:00
|
|
|
"os"
|
2022-05-30 23:12:18 +00:00
|
|
|
"strings"
|
2024-07-13 23:06:20 +00:00
|
|
|
"sync/atomic"
|
2023-01-28 13:13:04 +00:00
|
|
|
"time"
|
2016-04-20 01:37:53 +00:00
|
|
|
|
2021-10-12 07:25:13 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2024-07-17 23:26:35 +00:00
|
|
|
"github.com/urfave/cli/v3"
|
2024-07-13 23:06:20 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2017-06-28 17:21:22 +00:00
|
|
|
"google.golang.org/grpc"
|
2023-05-03 11:31:29 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
2024-05-24 20:35:04 +00:00
|
|
|
grpc_credentials "google.golang.org/grpc/credentials"
|
2022-01-29 15:04:50 +00:00
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
2018-01-08 15:28:38 +00:00
|
|
|
"google.golang.org/grpc/keepalive"
|
2017-07-19 21:46:03 +00:00
|
|
|
"google.golang.org/grpc/metadata"
|
2023-05-03 11:31:29 +00:00
|
|
|
"google.golang.org/grpc/status"
|
2017-06-28 17:21:22 +00:00
|
|
|
|
2023-12-08 07:15:08 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/agent"
|
2024-05-24 20:35:04 +00:00
|
|
|
agent_rpc "go.woodpecker-ci.org/woodpecker/v2/agent/rpc"
|
2023-12-08 07:15:08 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/rpc"
|
2023-12-31 22:29:56 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/shared/logger"
|
2023-12-08 07:15:08 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/shared/utils"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/version"
|
2016-04-20 01:37:53 +00:00
|
|
|
)
|
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
const (
|
|
|
|
reportHealthInterval = time.Second * 10
|
|
|
|
authInterceptorRefreshInterval = time.Minute * 30
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
shutdownTimeout = time.Second * 5
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
stopAgentFunc context.CancelCauseFunc = func(error) {}
|
|
|
|
shutdownCancelFunc context.CancelFunc = func() {}
|
|
|
|
shutdownCtx = context.Background()
|
|
|
|
)
|
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
2024-07-13 23:06:20 +00:00
|
|
|
agentCtx, ctxCancel := context.WithCancelCause(ctx)
|
|
|
|
stopAgentFunc = func(err error) {
|
|
|
|
msg := "shutdown of whole agent"
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg(msg)
|
|
|
|
} else {
|
|
|
|
log.Info().Msg(msg)
|
|
|
|
}
|
|
|
|
stopAgentFunc = func(error) {}
|
|
|
|
shutdownCtx, shutdownCancelFunc = context.WithTimeout(shutdownCtx, shutdownTimeout)
|
|
|
|
ctxCancel(err)
|
|
|
|
}
|
|
|
|
defer stopAgentFunc(nil)
|
|
|
|
defer shutdownCancelFunc()
|
|
|
|
|
|
|
|
serviceWaitingGroup := errgroup.Group{}
|
|
|
|
|
2023-07-12 16:51:40 +00:00
|
|
|
agentConfigPath := c.String("agent-config")
|
2017-07-19 21:46:03 +00:00
|
|
|
hostname := c.String("hostname")
|
|
|
|
if len(hostname) == 0 {
|
|
|
|
hostname, _ = os.Hostname()
|
|
|
|
}
|
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
counter.Polling = int(c.Int("max-workflows"))
|
2017-09-12 20:40:24 +00:00
|
|
|
counter.Running = 0
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
if c.Bool("healthcheck") {
|
2024-07-13 23:06:20 +00:00
|
|
|
serviceWaitingGroup.Go(
|
|
|
|
func() error {
|
|
|
|
server := &http.Server{Addr: c.String("healthcheck-addr")}
|
|
|
|
go func() {
|
|
|
|
<-agentCtx.Done()
|
|
|
|
log.Info().Msg("shutdown healthcheck server ...")
|
|
|
|
if err := server.Shutdown(shutdownCtx); err != nil { //nolint:contextcheck
|
|
|
|
log.Error().Err(err).Msg("shutdown healthcheck server failed")
|
|
|
|
} else {
|
|
|
|
log.Info().Msg("healthcheck server stopped")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
if err := server.ListenAndServe(); err != nil {
|
|
|
|
log.Error().Err(err).Msgf("cannot listen on address %s", c.String("healthcheck-addr"))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2017-09-12 18:25:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 15:04:50 +00:00
|
|
|
var transport grpc.DialOption
|
2022-01-31 14:38:00 +00:00
|
|
|
if c.Bool("grpc-secure") {
|
2024-07-19 05:24:11 +00:00
|
|
|
log.Trace().Msg("use ssl for grpc")
|
2024-05-24 20:35:04 +00:00
|
|
|
transport = grpc.WithTransportCredentials(grpc_credentials.NewTLS(&tls.Config{InsecureSkipVerify: c.Bool("grpc-skip-insecure")}))
|
2022-01-29 15:04:50 +00:00
|
|
|
} else {
|
|
|
|
transport = grpc.WithTransportCredentials(insecure.NewCredentials())
|
2020-05-16 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 15:37:21 +00:00
|
|
|
authConn, err := grpc.NewClient(
|
2017-06-28 17:21:22 +00:00
|
|
|
c.String("server"),
|
2020-05-16 18:56:24 +00:00
|
|
|
transport,
|
2023-01-28 13:13:04 +00:00
|
|
|
grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
|
|
|
Time: c.Duration("grpc-keepalive-time"),
|
|
|
|
Timeout: c.Duration("grpc-keepalive-timeout"),
|
2017-06-29 23:35:38 +00:00
|
|
|
}),
|
2023-01-28 13:13:04 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2024-07-19 05:24:11 +00:00
|
|
|
return fmt.Errorf("could not create new gRPC 'channel' for authentication: %w", err)
|
2023-01-28 13:13:04 +00:00
|
|
|
}
|
|
|
|
defer authConn.Close()
|
|
|
|
|
2023-07-12 16:51:40 +00:00
|
|
|
agentConfig := readAgentConfig(agentConfigPath)
|
|
|
|
|
2024-11-28 08:44:41 +00:00
|
|
|
agentToken := c.String("grpc-token")
|
2024-07-13 23:06:20 +00:00
|
|
|
grpcClientCtx, grpcClientCtxCancel := context.WithCancelCause(context.Background())
|
|
|
|
defer grpcClientCtxCancel(nil)
|
2024-05-24 20:35:04 +00:00
|
|
|
authClient := agent_rpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID)
|
2024-07-17 23:26:35 +00:00
|
|
|
authInterceptor, err := agent_rpc.NewAuthInterceptor(grpcClientCtx, authClient, authInterceptorRefreshInterval) //nolint:contextcheck
|
2023-01-28 13:13:04 +00:00
|
|
|
if err != nil {
|
2024-07-19 05:24:11 +00:00
|
|
|
return fmt.Errorf("could not create new auth interceptor: %w", err)
|
2023-01-28 13:13:04 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 15:37:21 +00:00
|
|
|
conn, err := grpc.NewClient(
|
2023-01-28 13:13:04 +00:00
|
|
|
c.String("server"),
|
|
|
|
transport,
|
2018-01-08 18:47:08 +00:00
|
|
|
grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
2022-01-31 14:38:00 +00:00
|
|
|
Time: c.Duration("grpc-keepalive-time"),
|
|
|
|
Timeout: c.Duration("grpc-keepalive-timeout"),
|
2018-01-08 18:47:08 +00:00
|
|
|
}),
|
2023-01-28 13:13:04 +00:00
|
|
|
grpc.WithUnaryInterceptor(authInterceptor.Unary()),
|
|
|
|
grpc.WithStreamInterceptor(authInterceptor.Stream()),
|
2017-03-16 10:14:02 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2024-07-19 05:24:11 +00:00
|
|
|
return fmt.Errorf("could not create new gRPC 'channel' for normal orchestration: %w", err)
|
2017-03-05 07:56:08 +00:00
|
|
|
}
|
2017-06-28 17:21:22 +00:00
|
|
|
defer conn.Close()
|
|
|
|
|
2024-09-18 14:29:56 +00:00
|
|
|
client := agent_rpc.NewGrpcClient(ctx, conn)
|
2024-07-13 23:06:20 +00:00
|
|
|
agentConfigPersisted := atomic.Bool{}
|
2017-03-05 07:56:08 +00:00
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
grpcCtx := metadata.NewOutgoingContext(grpcClientCtx, metadata.Pairs("hostname", hostname))
|
2016-09-29 21:45:13 +00:00
|
|
|
|
2023-03-19 21:42:21 +00:00
|
|
|
// check if grpc server version is compatible with agent
|
2024-07-17 23:26:35 +00:00
|
|
|
grpcServerVersion, err := client.Version(grpcCtx) //nolint:contextcheck
|
2023-03-19 21:42:21 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("could not get grpc server version")
|
|
|
|
return err
|
|
|
|
}
|
2024-05-24 20:35:04 +00:00
|
|
|
if grpcServerVersion.GrpcVersion != agent_rpc.ClientGrpcVersion {
|
2023-03-19 21:42:21 +00:00
|
|
|
err := errors.New("GRPC version mismatch")
|
2024-01-11 18:17:07 +00:00
|
|
|
log.Error().Err(err).Msgf("server version %s does report grpc version %d but we only understand %d",
|
2023-03-19 21:42:21 +00:00
|
|
|
grpcServerVersion.ServerVersion,
|
|
|
|
grpcServerVersion.GrpcVersion,
|
2024-05-24 20:35:04 +00:00
|
|
|
agent_rpc.ClientGrpcVersion)
|
2023-03-19 21:42:21 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-12-20 13:26:57 +00:00
|
|
|
// new engine
|
2024-07-17 23:26:35 +00:00
|
|
|
backendCtx := context.WithValue(agentCtx, types.CliCommand, c)
|
2024-02-08 15:33:22 +00:00
|
|
|
backendName := c.String("backend-engine")
|
2024-02-08 23:04:43 +00:00
|
|
|
backendEngine, err := backend.FindBackend(backendCtx, backends, backendName)
|
2022-09-03 18:41:23 +00:00
|
|
|
if err != nil {
|
2024-02-08 15:33:22 +00:00
|
|
|
log.Error().Err(err).Msgf("cannot find backend engine '%s'", backendName)
|
2022-09-03 18:41:23 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-12-20 13:26:57 +00:00
|
|
|
if !backendEngine.IsAvailable(backendCtx) {
|
|
|
|
log.Error().Str("engine", backendEngine.Name()).Msg("selected backend engine is unavailable")
|
|
|
|
return fmt.Errorf("selected backend engine %s is unavailable", backendEngine.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
// load engine (e.g. init api client)
|
2023-12-14 18:20:47 +00:00
|
|
|
engInfo, err := backendEngine.Load(backendCtx)
|
2023-11-01 14:38:37 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("cannot load backend engine")
|
|
|
|
return err
|
|
|
|
}
|
2023-12-14 18:20:47 +00:00
|
|
|
log.Debug().Msgf("loaded %s backend engine", backendEngine.Name())
|
2023-11-01 14:38:37 +00:00
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
maxWorkflows := int(c.Int("max-workflows"))
|
2024-10-06 15:13:41 +00:00
|
|
|
|
|
|
|
customLabels := make(map[string]string)
|
|
|
|
if err := stringSliceAddToMap(c.StringSlice("labels"), customLabels); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(customLabels) != 0 {
|
|
|
|
log.Debug().Msgf("custom labels detected: %#v", customLabels)
|
|
|
|
}
|
|
|
|
|
|
|
|
agentConfig.AgentID, err = client.RegisterAgent(grpcCtx, rpc.AgentInfo{ //nolint:contextcheck
|
|
|
|
Version: version.String(),
|
|
|
|
Backend: backendEngine.Name(),
|
|
|
|
Platform: engInfo.Platform,
|
|
|
|
Capacity: maxWorkflows,
|
|
|
|
CustomLabels: customLabels,
|
|
|
|
})
|
2023-01-28 13:13:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
serviceWaitingGroup.Go(func() error {
|
|
|
|
// we close grpc client context once unregister was handled
|
|
|
|
defer grpcClientCtxCancel(nil)
|
|
|
|
// we wait till agent context is done
|
|
|
|
<-agentCtx.Done()
|
|
|
|
// Remove stateless agents from server
|
|
|
|
if !agentConfigPersisted.Load() {
|
2024-10-06 15:13:41 +00:00
|
|
|
log.Debug().Msg("unregister agent from server ...")
|
2024-07-13 23:06:20 +00:00
|
|
|
// we want to run it explicit run when context got canceled so run it in background
|
|
|
|
err := client.UnregisterAgent(grpcClientCtx)
|
|
|
|
if err != nil {
|
|
|
|
log.Err(err).Msg("failed to unregister agent from server")
|
|
|
|
} else {
|
|
|
|
log.Info().Msg("agent unregistered from server")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2023-11-01 23:53:47 +00:00
|
|
|
if agentConfigPath != "" {
|
|
|
|
if err := writeAgentConfig(agentConfig, agentConfigPath); err == nil {
|
2024-07-13 23:06:20 +00:00
|
|
|
agentConfigPersisted.Store(true)
|
2023-11-01 23:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-02 15:22:05 +00:00
|
|
|
|
2024-10-06 15:13:41 +00:00
|
|
|
// set default labels ...
|
2023-04-03 10:30:52 +00:00
|
|
|
labels := map[string]string{
|
|
|
|
"hostname": hostname,
|
2023-11-01 14:38:37 +00:00
|
|
|
"platform": engInfo.Platform,
|
2023-12-14 18:20:47 +00:00
|
|
|
"backend": backendEngine.Name(),
|
2023-04-03 10:30:52 +00:00
|
|
|
"repo": "*", // allow all repos by default
|
|
|
|
}
|
2024-10-06 15:13:41 +00:00
|
|
|
// ... and let it overwrite by custom ones
|
|
|
|
maps.Copy(labels, customLabels)
|
2023-04-03 10:30:52 +00:00
|
|
|
|
2024-10-03 08:53:41 +00:00
|
|
|
log.Debug().Any("labels", labels).Msgf("agent configured with labels")
|
|
|
|
|
2023-04-03 10:30:52 +00:00
|
|
|
filter := rpc.Filter{
|
|
|
|
Labels: labels,
|
|
|
|
}
|
|
|
|
|
2024-01-11 18:17:07 +00:00
|
|
|
log.Debug().Msgf("agent registered with ID %d", agentConfig.AgentID)
|
2023-01-28 13:13:04 +00:00
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
serviceWaitingGroup.Go(func() error {
|
2023-01-28 13:13:04 +00:00
|
|
|
for {
|
2024-07-13 23:06:20 +00:00
|
|
|
err := client.ReportHealth(grpcCtx)
|
2023-01-28 13:13:04 +00:00
|
|
|
if err != nil {
|
2024-01-11 18:17:07 +00:00
|
|
|
log.Err(err).Msg("failed to report health")
|
2023-01-28 13:13:04 +00:00
|
|
|
}
|
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
select {
|
|
|
|
case <-agentCtx.Done():
|
|
|
|
log.Debug().Msg("terminating health reporting")
|
|
|
|
return nil
|
|
|
|
case <-time.After(reportHealthInterval):
|
|
|
|
}
|
2023-01-28 13:13:04 +00:00
|
|
|
}
|
2024-07-13 23:06:20 +00:00
|
|
|
})
|
2023-01-28 13:13:04 +00:00
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
for i := 0; i < maxWorkflows; i++ {
|
2023-07-20 18:39:20 +00:00
|
|
|
i := i
|
2024-07-13 23:06:20 +00:00
|
|
|
serviceWaitingGroup.Go(func() error {
|
|
|
|
runner := agent.NewRunner(client, filter, hostname, counter, &backendEngine)
|
2023-07-20 18:39:20 +00:00
|
|
|
log.Debug().Msgf("created new runner %d", i)
|
2022-03-08 15:21:43 +00:00
|
|
|
|
|
|
|
for {
|
2024-07-13 23:06:20 +00:00
|
|
|
if agentCtx.Err() != nil {
|
|
|
|
return nil
|
2021-11-26 02:34:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 15:38:53 +00:00
|
|
|
log.Debug().Msg("polling new steps")
|
2024-07-13 23:06:20 +00:00
|
|
|
if err := runner.Run(agentCtx, shutdownCtx); err != nil {
|
|
|
|
log.Error().Err(err).Msg("runner done with error")
|
|
|
|
return err
|
2017-03-16 10:14:02 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-13 23:06:20 +00:00
|
|
|
})
|
2016-04-20 01:37:53 +00:00
|
|
|
}
|
2016-05-24 01:47:44 +00:00
|
|
|
|
2022-09-03 18:41:23 +00:00
|
|
|
log.Info().Msgf(
|
2024-01-11 18:17:07 +00:00
|
|
|
"starting Woodpecker agent with version '%s' and backend '%s' using platform '%s' running up to %d pipelines in parallel",
|
2024-07-13 23:06:20 +00:00
|
|
|
version.String(), backendEngine.Name(), engInfo.Platform, maxWorkflows)
|
2022-09-03 18:41:23 +00:00
|
|
|
|
2024-07-13 23:06:20 +00:00
|
|
|
return serviceWaitingGroup.Wait()
|
2017-03-16 10:14:02 +00:00
|
|
|
}
|
2023-04-28 18:41:05 +00:00
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
func runWithRetry(backendEngines []types.Backend) func(ctx context.Context, c *cli.Command) error {
|
|
|
|
return func(ctx context.Context, c *cli.Command) error {
|
|
|
|
if err := logger.SetupGlobalLogger(ctx, c, true); err != nil {
|
2024-02-08 15:33:22 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-01-10 14:34:44 +00:00
|
|
|
|
2024-02-08 15:33:22 +00:00
|
|
|
initHealth()
|
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
retryCount := int(c.Int("connect-retry-count"))
|
2024-07-13 23:06:20 +00:00
|
|
|
retryDelay := c.Duration("connect-retry-delay")
|
2024-02-08 15:33:22 +00:00
|
|
|
var err error
|
|
|
|
for i := 0; i < retryCount; i++ {
|
2024-07-17 23:26:35 +00:00
|
|
|
if err = run(ctx, c, backendEngines); status.Code(err) == codes.Unavailable {
|
2024-02-08 15:33:22 +00:00
|
|
|
log.Warn().Err(err).Msg(fmt.Sprintf("cannot connect to server, retrying in %v", retryDelay))
|
|
|
|
time.Sleep(retryDelay)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
2023-05-03 11:31:29 +00:00
|
|
|
}
|
2024-02-08 15:33:22 +00:00
|
|
|
return err
|
2023-05-03 11:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 18:41:05 +00:00
|
|
|
func stringSliceAddToMap(sl []string, m map[string]string) error {
|
|
|
|
if m == nil {
|
|
|
|
m = make(map[string]string)
|
|
|
|
}
|
2024-02-14 22:22:31 +00:00
|
|
|
for _, v := range utils.StringSliceDeleteEmpty(sl) {
|
2024-03-15 17:00:25 +00:00
|
|
|
before, after, _ := strings.Cut(v, "=")
|
|
|
|
switch {
|
|
|
|
case before != "" && after != "":
|
|
|
|
m[before] = after
|
|
|
|
case before != "":
|
|
|
|
return fmt.Errorf("key '%s' does not have a value assigned", before)
|
2023-04-28 18:41:05 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("empty string in slice")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|