Explorar o código

make Duration wrapper publicly accessible

max furman %!s(int64=7) %!d(string=hai) anos
pai
achega
4b742042ee
Modificáronse 3 ficheiros con 13 adicións e 12 borrados
  1. 3 3
      authority/config.go
  2. 3 3
      authority/provisioner.go
  3. 7 6
      authority/types.go

+ 3 - 3
authority/config.go

@@ -26,9 +26,9 @@ var (
 	}
 	defaultDisableRenewal   = false
 	globalProvisionerClaims = ProvisionerClaims{
-		MinTLSDur:      &duration{5 * time.Minute},
-		MaxTLSDur:      &duration{24 * time.Hour},
-		DefaultTLSDur:  &duration{24 * time.Hour},
+		MinTLSDur:      &Duration{5 * time.Minute},
+		MaxTLSDur:      &Duration{24 * time.Hour},
+		DefaultTLSDur:  &Duration{24 * time.Hour},
 		DisableRenewal: &defaultDisableRenewal,
 	}
 )

+ 3 - 3
authority/provisioner.go

@@ -12,9 +12,9 @@ import (
 // ProvisionerClaims so that individual provisioners can override global claims.
 type ProvisionerClaims struct {
 	globalClaims   *ProvisionerClaims
-	MinTLSDur      *duration `json:"minTLSCertDuration,omitempty"`
-	MaxTLSDur      *duration `json:"maxTLSCertDuration,omitempty"`
-	DefaultTLSDur  *duration `json:"defaultTLSCertDuration,omitempty"`
+	MinTLSDur      *Duration `json:"minTLSCertDuration,omitempty"`
+	MaxTLSDur      *Duration `json:"maxTLSCertDuration,omitempty"`
+	DefaultTLSDur  *Duration `json:"defaultTLSCertDuration,omitempty"`
 	DisableRenewal *bool     `json:"disableRenewal,omitempty"`
 }
 

+ 7 - 6
authority/types.go

@@ -7,25 +7,26 @@ import (
 	"github.com/pkg/errors"
 )
 
-type duration struct {
+// Duration is a wrapper around Time.Duration to aid with marshal/unmarshal.
+type Duration struct {
 	time.Duration
 }
 
-// MarshalJSON parses a duration string and sets it to the duration.
+// MarshalJSON parses a Duration string and sets it to the duration.
 //
 // A duration string is a possibly signed sequence of decimal numbers, each with
 // optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m".
 // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
-func (d *duration) MarshalJSON() ([]byte, error) {
+func (d *Duration) MarshalJSON() ([]byte, error) {
 	return json.Marshal(d.String())
 }
 
-// UnmarshalJSON parses a duration string and sets it to the duration.
+// UnmarshalJSON parses a Duration string and sets it to the duration.
 //
-// A duration string is a possibly signed sequence of decimal numbers, each with
+// A Duration string is a possibly signed sequence of decimal numbers, each with
 // optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m".
 // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
-func (d *duration) UnmarshalJSON(data []byte) (err error) {
+func (d *Duration) UnmarshalJSON(data []byte) (err error) {
 	var s string
 	if err = json.Unmarshal(data, &s); err != nil {
 		return errors.Wrapf(err, "error unmarshalling %s", data)