mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-03-16 17:54:07 +01:00
Drop error only on purpose or else report back or log (#514)
- Remove Deadcode - Simplify Code - Drop error only on purpose
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/agent"
|
||||
@@ -46,7 +47,7 @@ func handleHeartbeat(w http.ResponseWriter, r *http.Request) {
|
||||
func handleVersion(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(200)
|
||||
w.Header().Add("Content-Type", "text/json")
|
||||
json.NewEncoder(w).Encode(versionResp{
|
||||
_ = json.NewEncoder(w).Encode(versionResp{
|
||||
Source: "https://github.com/woodpecker-ci/woodpecker",
|
||||
Version: version.String(),
|
||||
})
|
||||
@@ -59,7 +60,9 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
w.Header().Add("Content-Type", "text/json")
|
||||
counter.WriteTo(w)
|
||||
if _, err := counter.WriteTo(w); err != nil {
|
||||
log.Error().Err(err).Msg("handleStats")
|
||||
}
|
||||
}
|
||||
|
||||
type versionResp struct {
|
||||
|
||||
@@ -12,14 +12,6 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// WithContext returns a copy of parent context whose Done channel is closed
|
||||
// when an os interrupt signal is received.
|
||||
func WithContext(ctx context.Context) context.Context {
|
||||
return WithContextFunc(ctx, func() {
|
||||
println("interrupt received, terminating process")
|
||||
})
|
||||
}
|
||||
|
||||
// WithContextFunc returns a copy of parent context that is cancelled when
|
||||
// an os interrupt signal is received. The callback function f is invoked
|
||||
// before cancellation.
|
||||
|
||||
@@ -19,19 +19,21 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
godotenv.Load(".env")
|
||||
if err := godotenv.Load(".env"); err != nil {
|
||||
log.Error().Err(err).Msg("load godotenv failed")
|
||||
}
|
||||
app := cli.NewApp()
|
||||
app.Name = "woodpecker-server"
|
||||
app.Version = version.String()
|
||||
app.Usage = "woodpecker server"
|
||||
app.Action = loop
|
||||
app.Action = run
|
||||
app.Flags = flags
|
||||
app.Before = before
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ import (
|
||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||
)
|
||||
|
||||
func loop(c *cli.Context) error {
|
||||
func run(c *cli.Context) error {
|
||||
|
||||
if c.Bool("pretty") {
|
||||
log.Logger = log.Output(
|
||||
@@ -224,7 +224,9 @@ func loop(c *cli.Context) error {
|
||||
}
|
||||
|
||||
dir := cacheDir()
|
||||
os.MkdirAll(dir, 0700)
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
manager := &autocert.Manager{
|
||||
Prompt: autocert.AcceptTOS,
|
||||
@@ -259,7 +261,9 @@ func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
|
||||
server.Config.Services.Queue = setupQueue(c, v)
|
||||
server.Config.Services.Logs = logging.New()
|
||||
server.Config.Services.Pubsub = pubsub.New()
|
||||
server.Config.Services.Pubsub.Create(context.Background(), "topic/events")
|
||||
if err := server.Config.Services.Pubsub.Create(context.Background(), "topic/events"); err != nil {
|
||||
log.Error().Err(err).Msg("could not create pubsub service")
|
||||
}
|
||||
server.Config.Services.Registries = setupRegistryService(c, v)
|
||||
server.Config.Services.Secrets = setupSecretService(c, v)
|
||||
server.Config.Services.Senders = sender.New(v, v)
|
||||
|
||||
Reference in New Issue
Block a user