github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/upload/upload.go (about) 1 // Package upload provides a Pipe that push using HTTP. 2 package upload 3 4 import ( 5 "fmt" 6 h "net/http" 7 8 "github.com/goreleaser/goreleaser/internal/http" 9 "github.com/goreleaser/goreleaser/internal/pipe" 10 "github.com/goreleaser/goreleaser/pkg/context" 11 ) 12 13 // Pipe for http publishing. 14 type Pipe struct{} 15 16 // String returns the description of the pipe. 17 func (Pipe) String() string { return "http upload" } 18 func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Uploads) == 0 } 19 20 // Default sets the pipe defaults. 21 func (Pipe) Default(ctx *context.Context) error { 22 return http.Defaults(ctx.Config.Uploads) 23 } 24 25 // Publish artifacts. 26 func (Pipe) Publish(ctx *context.Context) error { 27 // Check requirements for every instance we have configured. 28 // If not fulfilled, we can skip this pipeline 29 for _, instance := range ctx.Config.Uploads { 30 instance := instance 31 if skip := http.CheckConfig(ctx, &instance, "upload"); skip != nil { 32 return pipe.Skip(skip.Error()) 33 } 34 } 35 36 return http.Upload(ctx, ctx.Config.Uploads, "upload", func(res *h.Response) error { 37 if c := res.StatusCode; c < 200 || 299 < c { 38 return fmt.Errorf("unexpected http response status: %s", res.Status) 39 } 40 return nil 41 }) 42 }