aboutsummaryrefslogtreecommitdiff
path: root/generated.go.in
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-03-11 19:38:27 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-03-11 19:41:33 +0100
commitd23b4052c0866698b14ac13ac98581d9f5440a9b (patch)
tree51c93559594f8fd5136fd51b7397a30415ea93aa /generated.go.in
parentaaf61ac55e18a04fd68b9b6ee4fd4fce49659eeb (diff)
downloadgo-schwift-d23b4052c0866698b14ac13ac98581d9f5440a9b.tar.gz
revamp the Headers API
1. Move common methods of AccountHeaders, ContainerHeaders, ObjectHeaders into a base type Headers. 2. Fold Headers into RequestOptions to remove one of the two optional arguments on request methods. The new Headers.ToOpts() method offers a nice experience for users passing Headers to request methods. The Update() methods keep the explicit Headers argument since the Headers argument is not optional there. The only downside is that we lose a bit of type-safety because RequestOptions takes any Headers instance, so e.g. ContainerHeaders could be passed to Object.Upload(). I believe the benefits outweigh this problem.
Diffstat (limited to 'generated.go.in')
-rw-r--r--generated.go.in50
1 files changed, 8 insertions, 42 deletions
diff --git a/generated.go.in b/generated.go.in
index 85c257a..2858bcb 100644
--- a/generated.go.in
+++ b/generated.go.in
@@ -57,54 +57,20 @@
package schwift
-import "net/textproto"
-
{{- range $htype, $hmeta := . }}
//{{$htype}}Headers contains the headers for a schwift.{{$htype}} instance.
//
//To read and write well-known headers, use the methods on this type.
-//To read and write arbitary headers, use the http.Header-like methods Get(),
-//Set(), Clear(), Del().
-type {{$htype}}Headers map[string]string
-
-//Clear sets the value for the specified header to the empty string. When the
-//Headers instance is then sent to the server with Update(), the server will
-//delete the value for that header; cf. Del().
-func (h {{$htype}}Headers) Clear(key string) {
- h[textproto.CanonicalMIMEHeaderKey(key)] = ""
-}
-{{/* */}}
-{{- if eq $htype "Object" }}
-//Del deletes a key from the Headers instance. When the Headers instance
-//is then sent to the server with Update(), Del() has different effects
-//depending on context because of Swift's inconsistent API:
-//
-//For most writable attributes, a key which has been deleted with Del() will
-//remain unchanged on the server. To remove the key on the server, use Clear()
-//instead.
-//
-//For object metadata (but not other object attributes), deleting a key will
-//cause that key to be deleted on the server. Del() is identical to Clear() in
-//this case.
-{{- else }}
-//Del deletes a key from the Headers instance. When the Headers instance is
-//then sent to the server with Update(), a key which has been deleted with
-//Del() will remain unchanged on the server.
-{{- end }}
-func (h {{$htype}}Headers) Del(key string) {
- delete(h, textproto.CanonicalMIMEHeaderKey(key))
-}
-
-//Get returns the value for the specified header.
-func (h {{$htype}}Headers) Get(key string) string {
- return h[textproto.CanonicalMIMEHeaderKey(key)]
+//To read and write arbitary headers, use the methods on the Headers supertype.
+type {{$htype}}Headers struct {
+ Headers
}
-//Set sets a new value for the specified header. Any existing value will be
-//overwritten.
-func (h {{$htype}}Headers) Set(key, value string) {
- h[textproto.CanonicalMIMEHeaderKey(key)] = value
+//New{{$htype}}Headers creates a new {{$htype}}Headers instance. The return value
+//will have the Headers attribute initialized to a non-nil map.
+func New{{$htype}}Headers() {{$htype}}Headers {
+ return {{$htype}}Headers{make(Headers)}
}
//Validate returns MalformedHeaderError if the value of any well-known header
@@ -125,7 +91,7 @@ func (h {{$htype}}Headers) Validate() error {
//{{$field.Attribute}} provides type-safe access to {{$field.Header}} headers.
func (h {{$htype}}Headers) {{$field.Attribute}}() Field{{$field.Type}} {
- return Field{{$field.Type}}{h, "{{$field.Header}}"}
+ return Field{{$field.Type}}{h.Headers, "{{$field.Header}}"}
}
{{- end }}
{{- end }}