github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/pipe/put/put.go (about)

     1  // Package put provides a Pipe that push using HTTP PUT
     2  package put
     3  
     4  import (
     5  	h "net/http"
     6  
     7  	"github.com/goreleaser/goreleaser/internal/http"
     8  	"github.com/goreleaser/goreleaser/internal/pipe"
     9  	"github.com/goreleaser/goreleaser/pkg/context"
    10  	"github.com/pkg/errors"
    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 {
    18  	return "releasing with HTTP PUT"
    19  }
    20  
    21  // Default sets the pipe defaults
    22  func (Pipe) Default(ctx *context.Context) error {
    23  	return http.Defaults(ctx.Config.Puts)
    24  }
    25  
    26  // Publish artifacts
    27  func (Pipe) Publish(ctx *context.Context) error {
    28  	if len(ctx.Config.Puts) == 0 {
    29  		return pipe.Skip("put section is not configured")
    30  	}
    31  
    32  	// Check requirements for every instance we have configured.
    33  	// If not fulfilled, we can skip this pipeline
    34  	for _, instance := range ctx.Config.Puts {
    35  		if skip := http.CheckConfig(ctx, &instance, "put"); skip != nil {
    36  			return pipe.Skip(skip.Error())
    37  		}
    38  	}
    39  
    40  	return http.Upload(ctx, ctx.Config.Puts, "put", func(res *h.Response) error {
    41  		if c := res.StatusCode; c < 200 || 299 < c {
    42  			return errors.Errorf("unexpected http response status: %s", res.Status)
    43  		}
    44  		return nil
    45  	})
    46  
    47  }