github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/binding/decoders/decoders.go (about)

     1  package decoders
     2  
     3  import (
     4  	"sync"
     5  	"time"
     6  )
     7  
     8  var (
     9  	lock = &sync.RWMutex{}
    10  
    11  	// timeFormats are the base time formats supported by the time.Time and
    12  	// nulls.Time Decoders you can prepend custom formats to this list
    13  	// by using RegisterTimeFormats.
    14  	timeFormats = []string{
    15  		time.RFC3339,
    16  		"01/02/2006",
    17  		"2006-01-02",
    18  		"2006-01-02T15:04",
    19  		time.ANSIC,
    20  		time.UnixDate,
    21  		time.RubyDate,
    22  		time.RFC822,
    23  		time.RFC822Z,
    24  		time.RFC850,
    25  		time.RFC1123,
    26  		time.RFC1123Z,
    27  		time.RFC3339Nano,
    28  		time.Kitchen,
    29  		time.Stamp,
    30  		time.StampMilli,
    31  		time.StampMicro,
    32  		time.StampNano,
    33  	}
    34  )
    35  
    36  // RegisterTimeFormats allows to add custom time layouts that
    37  // the binder will be able to use for decoding.
    38  func RegisterTimeFormats(layouts ...string) {
    39  	lock.Lock()
    40  	defer lock.Unlock()
    41  
    42  	timeFormats = append(layouts, timeFormats...)
    43  }