func (b Base64) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	b.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( b Base64 ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer b . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }

// MarshalJSON returns the Base64 as JSON


func (b Base64) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(base64.StdEncoding.EncodeToString([]byte(b)))
}

func ( b Base64 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( base64 . StdEncoding . EncodeToString ( [ ] byte ( b ) ) ) }

// MarshalEasyJSON writes the Base64 to a easyjson.Writer

MarshalEasyJSON writes the Base64 to a easyjson . Writer


func (b *Base64) UnmarshalJSON(data []byte) error {
	l := jlexer.Lexer{Data: data}
	b.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( b * Base64 ) UnmarshalJSON ( data [ ] byte ) error { l := jlexer . Lexer { Data : data } b . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the Base64 from JSON


func (b *Base64) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		enc := base64.StdEncoding
		dbuf := make([]byte, enc.DecodedLen(len(data)))

		n, err := enc.Decode(dbuf, []byte(data))
		if err != nil {
			in.AddError(err)
			return
		}

		*b = dbuf[:n]
	}
}

func ( b * Base64 ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { enc := base64 . StdEncoding dbuf := make ( [ ] byte , enc . DecodedLen ( len ( data ) ) ) n , err := enc . Decode ( dbuf , [ ] byte ( data ) ) if err != nil { in . AddError ( err ) return } * b = dbuf [ : n ] } }

// UnmarshalEasyJSON sets the Base64 from a easyjson.Lexer

UnmarshalEasyJSON sets the Base64 from a easyjson . Lexer


func (b *Base64) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		*b = Base64(data)
		return nil
	}

	return errors.New("couldn't unmarshal bson raw value as Base64")
}

func ( b * Base64 ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { * b = Base64 ( data ) return nil } return errors . New ( " " ) }

// SetBSON sets the Base64 from raw bson data


func (b *Base64) DeepCopy() *Base64 {
	if b == nil {
		return nil
	}
	out := new(Base64)
	b.DeepCopyInto(out)
	return out
}

func ( b * Base64 ) DeepCopy ( ) * Base64 { if b == nil { return nil } out := new ( Base64 ) b . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new Base64.

DeepCopy copies the receiver into a new Base64 .


func (u URI) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	u.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( u URI ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer u . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }


func (u URI) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u URI ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the URI to a easyjson.Writer

MarshalEasyJSON writes the URI to a easyjson . Writer


func (u *URI) UnmarshalJSON(data []byte) error {
	l := jlexer.Lexer{Data: data}
	u.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( u * URI ) UnmarshalJSON ( data [ ] byte ) error { l := jlexer . Lexer { Data : data } u . UnmarshalEasyJSON ( & l ) return l . Error ( ) }


func (u *URI) DeepCopy() *URI {
	if u == nil {
		return nil
	}
	out := new(URI)
	u.DeepCopyInto(out)
	return out
}

func ( u * URI ) DeepCopy ( ) * URI { if u == nil { return nil } out := new ( URI ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new URI.

DeepCopy copies the receiver into a new URI .


func (e Email) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	e.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( e Email ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer e . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }

// MarshalJSON returns the Email as JSON


func (e Email) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(e))
}

func ( e Email ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( e ) ) }

// MarshalEasyJSON writes the Email to a easyjson.Writer

MarshalEasyJSON writes the Email to a easyjson . Writer


func (e *Email) UnmarshalJSON(data []byte) error {
	l := jlexer.Lexer{Data: data}
	e.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( e * Email ) UnmarshalJSON ( data [ ] byte ) error { l := jlexer . Lexer { Data : data } e . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the Email from JSON


func (e *Email) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		*e = Email(data)
	}
}

func ( e * Email ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { * e = Email ( data ) } }

// UnmarshalEasyJSON sets the Email from a easyjson.Lexer

UnmarshalEasyJSON sets the Email from a easyjson . Lexer


func (e *Email) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		*e = Email(data)
		return nil
	}

	return errors.New("couldn't unmarshal bson raw value as Email")
}

func ( e * Email ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { * e = Email ( data ) return nil } return errors . New ( " " ) }

// SetBSON sets the Email from raw bson data


func (e *Email) DeepCopy() *Email {
	if e == nil {
		return nil
	}
	out := new(Email)
	e.DeepCopyInto(out)
	return out
}

func ( e * Email ) DeepCopy ( ) * Email { if e == nil { return nil } out := new ( Email ) e . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new Email.

DeepCopy copies the receiver into a new Email .


func (h Hostname) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(h))
}

func ( h Hostname ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( h ) ) }

// MarshalEasyJSON writes the Hostname to a easyjson.Writer

MarshalEasyJSON writes the Hostname to a easyjson . Writer


func (h *Hostname) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		*h = Hostname(data)
		return nil
	}

	return errors.New("couldn't unmarshal bson raw value as Hostname")
}

func ( h * Hostname ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { * h = Hostname ( data ) return nil } return errors . New ( " " ) }

// SetBSON sets the Hostname from raw bson data


func (h *Hostname) DeepCopy() *Hostname {
	if h == nil {
		return nil
	}
	out := new(Hostname)
	h.DeepCopyInto(out)
	return out
}

func ( h * Hostname ) DeepCopy ( ) * Hostname { if h == nil { return nil } out := new ( Hostname ) h . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new Hostname.

DeepCopy copies the receiver into a new Hostname .


func (u IPv4) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u IPv4 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the IPv4 to a easyjson.Writer

MarshalEasyJSON writes the IPv4 to a easyjson . Writer


func (u *IPv4) DeepCopy() *IPv4 {
	if u == nil {
		return nil
	}
	out := new(IPv4)
	u.DeepCopyInto(out)
	return out
}

func ( u * IPv4 ) DeepCopy ( ) * IPv4 { if u == nil { return nil } out := new ( IPv4 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new IPv4.

DeepCopy copies the receiver into a new IPv4 .


func (u IPv6) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u IPv6 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the IPv6 to a easyjson.Writer

MarshalEasyJSON writes the IPv6 to a easyjson . Writer


func (u *IPv6) DeepCopy() *IPv6 {
	if u == nil {
		return nil
	}
	out := new(IPv6)
	u.DeepCopyInto(out)
	return out
}

func ( u * IPv6 ) DeepCopy ( ) * IPv6 { if u == nil { return nil } out := new ( IPv6 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new IPv6.

DeepCopy copies the receiver into a new IPv6 .


func (u CIDR) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u CIDR ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the CIDR to a easyjson.Writer

MarshalEasyJSON writes the CIDR to a easyjson . Writer


func (u *CIDR) DeepCopy() *CIDR {
	if u == nil {
		return nil
	}
	out := new(CIDR)
	u.DeepCopyInto(out)
	return out
}

func ( u * CIDR ) DeepCopy ( ) * CIDR { if u == nil { return nil } out := new ( CIDR ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new CIDR.

DeepCopy copies the receiver into a new CIDR .


func (u MAC) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u MAC ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the MAC to a easyjson.Writer

MarshalEasyJSON writes the MAC to a easyjson . Writer


func (u *MAC) DeepCopy() *MAC {
	if u == nil {
		return nil
	}
	out := new(MAC)
	u.DeepCopyInto(out)
	return out
}

func ( u * MAC ) DeepCopy ( ) * MAC { if u == nil { return nil } out := new ( MAC ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new MAC.

DeepCopy copies the receiver into a new MAC .


func (u UUID) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u UUID ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the UUID to a easyjson.Writer

MarshalEasyJSON writes the UUID to a easyjson . Writer


func (u *UUID) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		*u = UUID(data)
		return nil
	}

	return errors.New("couldn't unmarshal bson raw value as UUID")
}

func ( u * UUID ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { * u = UUID ( data ) return nil } return errors . New ( " " ) }

// SetBSON sets the UUID from raw bson data


func (u *UUID) DeepCopy() *UUID {
	if u == nil {
		return nil
	}
	out := new(UUID)
	u.DeepCopyInto(out)
	return out
}

func ( u * UUID ) DeepCopy ( ) * UUID { if u == nil { return nil } out := new ( UUID ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new UUID.

DeepCopy copies the receiver into a new UUID .


func (u UUID3) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u UUID3 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the UUID3 to a easyjson.Writer

MarshalEasyJSON writes the UUID3 to a easyjson . Writer


func (u *UUID3) DeepCopy() *UUID3 {
	if u == nil {
		return nil
	}
	out := new(UUID3)
	u.DeepCopyInto(out)
	return out
}

func ( u * UUID3 ) DeepCopy ( ) * UUID3 { if u == nil { return nil } out := new ( UUID3 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new UUID3.

DeepCopy copies the receiver into a new UUID3 .


func (u UUID4) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u UUID4 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the UUID4 to a easyjson.Writer

MarshalEasyJSON writes the UUID4 to a easyjson . Writer


func (u *UUID4) UnmarshalJSON(data []byte) error {
	if string(data) == jsonNull {
		return nil
	}
	l := jlexer.Lexer{Data: data}
	u.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( u * UUID4 ) UnmarshalJSON ( data [ ] byte ) error { if string ( data ) == jsonNull { return nil } l := jlexer . Lexer { Data : data } u . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the UUID4 from JSON


func (u *UUID4) DeepCopy() *UUID4 {
	if u == nil {
		return nil
	}
	out := new(UUID4)
	u.DeepCopyInto(out)
	return out
}

func ( u * UUID4 ) DeepCopy ( ) * UUID4 { if u == nil { return nil } out := new ( UUID4 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new UUID4.

DeepCopy copies the receiver into a new UUID4 .


func (u UUID5) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u UUID5 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the UUID5 to a easyjson.Writer

MarshalEasyJSON writes the UUID5 to a easyjson . Writer


func (u *UUID5) DeepCopy() *UUID5 {
	if u == nil {
		return nil
	}
	out := new(UUID5)
	u.DeepCopyInto(out)
	return out
}

func ( u * UUID5 ) DeepCopy ( ) * UUID5 { if u == nil { return nil } out := new ( UUID5 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new UUID5.

DeepCopy copies the receiver into a new UUID5 .


func (u ISBN) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u ISBN ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the ISBN to a easyjson.Writer

MarshalEasyJSON writes the ISBN to a easyjson . Writer


func (u *ISBN) DeepCopy() *ISBN {
	if u == nil {
		return nil
	}
	out := new(ISBN)
	u.DeepCopyInto(out)
	return out
}

func ( u * ISBN ) DeepCopy ( ) * ISBN { if u == nil { return nil } out := new ( ISBN ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new ISBN.

DeepCopy copies the receiver into a new ISBN .


func (u ISBN10) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u ISBN10 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the ISBN10 to a easyjson.Writer

MarshalEasyJSON writes the ISBN10 to a easyjson . Writer


func (u *ISBN10) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		*u = ISBN10(data)
	}
}

func ( u * ISBN10 ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { * u = ISBN10 ( data ) } }

// UnmarshalEasyJSON sets the ISBN10 from a easyjson.Lexer

UnmarshalEasyJSON sets the ISBN10 from a easyjson . Lexer


func (u *ISBN10) DeepCopy() *ISBN10 {
	if u == nil {
		return nil
	}
	out := new(ISBN10)
	u.DeepCopyInto(out)
	return out
}

func ( u * ISBN10 ) DeepCopy ( ) * ISBN10 { if u == nil { return nil } out := new ( ISBN10 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new ISBN10.

DeepCopy copies the receiver into a new ISBN10 .


func (u ISBN13) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u ISBN13 ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the ISBN13 to a easyjson.Writer

MarshalEasyJSON writes the ISBN13 to a easyjson . Writer


func (u *ISBN13) DeepCopy() *ISBN13 {
	if u == nil {
		return nil
	}
	out := new(ISBN13)
	u.DeepCopyInto(out)
	return out
}

func ( u * ISBN13 ) DeepCopy ( ) * ISBN13 { if u == nil { return nil } out := new ( ISBN13 ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new ISBN13.

DeepCopy copies the receiver into a new ISBN13 .


func (u CreditCard) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u CreditCard ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the CreditCard to a easyjson.Writer

MarshalEasyJSON writes the CreditCard to a easyjson . Writer


func (u *CreditCard) DeepCopy() *CreditCard {
	if u == nil {
		return nil
	}
	out := new(CreditCard)
	u.DeepCopyInto(out)
	return out
}

func ( u * CreditCard ) DeepCopy ( ) * CreditCard { if u == nil { return nil } out := new ( CreditCard ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new CreditCard.

DeepCopy copies the receiver into a new CreditCard .


func (u SSN) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}

func ( u SSN ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( u ) ) }

// MarshalEasyJSON writes the SSN to a easyjson.Writer

MarshalEasyJSON writes the SSN to a easyjson . Writer


func (u *SSN) DeepCopy() *SSN {
	if u == nil {
		return nil
	}
	out := new(SSN)
	u.DeepCopyInto(out)
	return out
}

func ( u * SSN ) DeepCopy ( ) * SSN { if u == nil { return nil } out := new ( SSN ) u . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new SSN.

DeepCopy copies the receiver into a new SSN .


func (h HexColor) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	h.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( h HexColor ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer h . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }

// MarshalJSON returns the HexColor as JSON


func (h HexColor) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(h))
}

func ( h HexColor ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( h ) ) }

// MarshalEasyJSON writes the HexColor to a easyjson.Writer

MarshalEasyJSON writes the HexColor to a easyjson . Writer


func (h *HexColor) UnmarshalJSON(data []byte) error {
	l := jlexer.Lexer{Data: data}
	h.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( h * HexColor ) UnmarshalJSON ( data [ ] byte ) error { l := jlexer . Lexer { Data : data } h . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the HexColor from JSON


func (h *HexColor) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		*h = HexColor(data)
	}
}

func ( h * HexColor ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { * h = HexColor ( data ) } }

// UnmarshalEasyJSON sets the HexColor from a easyjson.Lexer

UnmarshalEasyJSON sets the HexColor from a easyjson . Lexer


func (h *HexColor) DeepCopy() *HexColor {
	if h == nil {
		return nil
	}
	out := new(HexColor)
	h.DeepCopyInto(out)
	return out
}

func ( h * HexColor ) DeepCopy ( ) * HexColor { if h == nil { return nil } out := new ( HexColor ) h . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new HexColor.

DeepCopy copies the receiver into a new HexColor .


func (r RGBColor) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(r))
}

func ( r RGBColor ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( r ) ) }

// MarshalEasyJSON writes the RGBColor to a easyjson.Writer

MarshalEasyJSON writes the RGBColor to a easyjson . Writer


func (r *RGBColor) UnmarshalJSON(data []byte) error {
	l := jlexer.Lexer{Data: data}
	r.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( r * RGBColor ) UnmarshalJSON ( data [ ] byte ) error { l := jlexer . Lexer { Data : data } r . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the RGBColor from JSON


func (r *RGBColor) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		*r = RGBColor(data)
	}
}

func ( r * RGBColor ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { * r = RGBColor ( data ) } }

// UnmarshalEasyJSON sets the RGBColor from a easyjson.Lexer

UnmarshalEasyJSON sets the RGBColor from a easyjson . Lexer


func (r *RGBColor) DeepCopy() *RGBColor {
	if r == nil {
		return nil
	}
	out := new(RGBColor)
	r.DeepCopyInto(out)
	return out
}

func ( r * RGBColor ) DeepCopy ( ) * RGBColor { if r == nil { return nil } out := new ( RGBColor ) r . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new RGBColor.

DeepCopy copies the receiver into a new RGBColor .


func (r Password) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	r.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( r Password ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer r . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }

// MarshalJSON returns the Password as JSON


func (r Password) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(r))
}

func ( r Password ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( string ( r ) ) }

// MarshalEasyJSON writes the Password to a easyjson.Writer

MarshalEasyJSON writes the Password to a easyjson . Writer


func (r *Password) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		*r = Password(data)
		return nil
	}

	return errors.New("couldn't unmarshal bson raw value as Password")
}

func ( r * Password ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { * r = Password ( data ) return nil } return errors . New ( " " ) }

// SetBSON sets the Password from raw bson data


func (r *Password) DeepCopy() *Password {
	if r == nil {
		return nil
	}
	out := new(Password)
	r.DeepCopyInto(out)
	return out
}

func ( r * Password ) DeepCopy ( ) * Password { if r == nil { return nil } out := new ( Password ) r . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new Password.

DeepCopy copies the receiver into a new Password .


func IsDateTime(str string) bool {
	if len(str) < 4 {
		return false
	}
	s := strings.Split(strings.ToLower(str), "t")
	if len(s) < 2 || !IsDate(s[0]) {
		return false
	}

	matches := rxDateTime.FindAllStringSubmatch(s[1], -1)
	if len(matches) == 0 || len(matches[0]) == 0 {
		return false
	}
	m := matches[0]
	res := m[1] <= "23" && m[2] <= "59" && m[3] <= "59"
	return res
}

func IsDateTime ( str string ) bool { if len ( str ) < 4 { return false } s := strings . Split ( strings . ToLower ( str ) , " " ) if len ( s ) < 2 || ! IsDate ( s [ 0 ] ) { return false } matches := rxDateTime . FindAllStringSubmatch ( s [ 1 ] , - 1 ) if len ( matches ) == 0 || len ( matches [ 0 ] ) == 0 { return false } m := matches [ 0 ] res := m [ 1 ] <= " " && m [ 2 ] <= " " && m [ 3 ] <= " " return res }

// IsDateTime returns true when the string is a valid date-time

IsDateTime returns true when the string is a valid date - time


func ParseDateTime(data string) (DateTime, error) {
	if data == "" {
		return NewDateTime(), nil
	}
	var lastError error
	for _, layout := range dateTimeFormats {
		dd, err := time.Parse(layout, data)
		if err != nil {
			lastError = err
			continue
		}
		lastError = nil
		return DateTime(dd), nil
	}
	return DateTime{}, lastError
}

func ParseDateTime ( data string ) ( DateTime , error ) { if data == " " { return NewDateTime ( ) , nil } var lastError error for _ , layout := range dateTimeFormats { dd , err := time . Parse ( layout , data ) if err != nil { lastError = err continue } lastError = nil return DateTime ( dd ) , nil } return DateTime { } , lastError }

// ParseDateTime parses a string that represents an ISO8601 time or a unix epoch


func (t *DateTime) UnmarshalText(text []byte) error {
	tt, err := ParseDateTime(string(text))
	if err != nil {
		return err
	}
	*t = tt
	return nil
}

func ( t * DateTime ) UnmarshalText ( text [ ] byte ) error { tt , err := ParseDateTime ( string ( text ) ) if err != nil { return err } * t = tt return nil }

// UnmarshalText implements the text unmarshaller interface


func (t *DateTime) Scan(raw interface{}) error {
	// TODO: case int64: and case float64: ?
	switch v := raw.(type) {
	case []byte:
		return t.UnmarshalText(v)
	case string:
		return t.UnmarshalText([]byte(v))
	case time.Time:
		*t = DateTime(v)
	case nil:
		*t = DateTime{}
	default:
		return fmt.Errorf("cannot sql.Scan() strfmt.DateTime from: %#v", v)
	}

	return nil
}

// Scan scans a DateTime value from database driver type.

Scan scans a DateTime value from database driver type .


func (t DateTime) Value() (driver.Value, error) {
	return driver.Value(t.String()), nil
}

func ( t DateTime ) Value ( ) ( driver . Value , error ) { return driver . Value ( t . String ( ) ) , nil }

// Value converts DateTime to a primitive value ready to written to a database.

Value converts DateTime to a primitive value ready to written to a database .


func (t DateTime) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	t.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( t DateTime ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer t . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }

// MarshalJSON returns the DateTime as JSON


func (t DateTime) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(time.Time(t).Format(MarshalFormat))
}

func ( t DateTime ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( time . Time ( t ) . Format ( MarshalFormat ) ) }

// MarshalEasyJSON writes the DateTime to a easyjson.Writer

MarshalEasyJSON writes the DateTime to a easyjson . Writer


func (t *DateTime) UnmarshalJSON(data []byte) error {
	if string(data) == jsonNull {
		return nil
	}
	l := jlexer.Lexer{Data: data}
	t.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( t * DateTime ) UnmarshalJSON ( data [ ] byte ) error { if string ( data ) == jsonNull { return nil } l := jlexer . Lexer { Data : data } t . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the DateTime from JSON


func (t *DateTime) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		tt, err := ParseDateTime(data)
		if err != nil {
			in.AddError(err)
			return
		}
		*t = tt
	}
}

func ( t * DateTime ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { tt , err := ParseDateTime ( data ) if err != nil { in . AddError ( err ) return } * t = tt } }

// UnmarshalEasyJSON sets the DateTime from a easyjson.Lexer

UnmarshalEasyJSON sets the DateTime from a easyjson . Lexer


func (t *DateTime) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		var err error
		*t, err = ParseDateTime(data)
		return err
	}

	return errors.New("couldn't unmarshal bson raw value as Duration")
}

func ( t * DateTime ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { var err error * t , err = ParseDateTime ( data ) return err } return errors . New ( " " ) }

// SetBSON sets the DateTime from raw bson data


func (t *DateTime) DeepCopy() *DateTime {
	if t == nil {
		return nil
	}
	out := new(DateTime)
	t.DeepCopyInto(out)
	return out
}

func ( t * DateTime ) DeepCopy ( ) * DateTime { if t == nil { return nil } out := new ( DateTime ) t . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new DateTime.

DeepCopy copies the receiver into a new DateTime .


func IsDuration(str string) bool {
	_, err := ParseDuration(str)
	return err == nil
}

func IsDuration ( str string ) bool { _ , err := ParseDuration ( str ) return err == nil }

// IsDuration returns true if the provided string is a valid duration


func ParseDuration(cand string) (time.Duration, error) {
	if dur, err := time.ParseDuration(cand); err == nil {
		return dur, nil
	}

	var dur time.Duration
	ok := false
	for _, match := range durationMatcher.FindAllStringSubmatch(cand, -1) {

		factor, err := strconv.Atoi(match[2]) // converts string to int
		if err != nil {
			return 0, err
		}
		unit := strings.ToLower(strings.TrimSpace(match[3]))

		for _, variants := range timeUnits {
			last := len(variants) - 1
			multiplier := timeMultiplier[variants[0]]

			for i, variant := range variants {
				if (last == i && strings.HasPrefix(unit, variant)) || strings.EqualFold(variant, unit) {
					ok = true
					dur += (time.Duration(factor) * multiplier)
				}
			}
		}
	}

	if ok {
		return dur, nil
	}
	return 0, fmt.Errorf("unable to parse %s as duration", cand)
}

func
ParseDuration
(
cand
string
)
(
time
.
Duration
,
error
)
{
if
dur
,
err
:=
time
.
ParseDuration
(
cand
)
;
err
==
{
return
dur
,
}
var
dur
time
.
Duration
ok
:=
false
for
_
,
match
:=
range
durationMatcher
.
FindAllStringSubmatch
(
cand
,
1
)
{
factor
,
err
:=
strconv
.
Atoi
(
match
[
2
]
)
// converts string to int
if
err
!=
{
return
0
,
err
}
unit
:=
strings
.
ToLower
(
strings
.
TrimSpace
(
match
[
3
]
)
)
for
_
,
variants
:=
range
timeUnits
{
last
:=
len
(
variants
)
1
multiplier
:=
timeMultiplier
[
variants
[
0
]
]
for
i
,
variant
:=
range
variants
{
if
(
last
==
i
&&
strings
.
HasPrefix
(
unit
,
variant
)
)
||
strings
.
EqualFold
(
variant
,
unit
)
{
ok
=
true
dur
+=
(
time
.
Duration
(
factor
)
*
multiplier
)
}
}
}
}
if
ok
{
return
dur
,
}
return
0
,
fmt
.
Errorf
(
"
"
,
cand
)
}

// ParseDuration parses a duration from a string, compatible with scala duration syntax

ParseDuration parses a duration from a string compatible with scala duration syntax


func (d *Duration) Scan(raw interface{}) error {
	switch v := raw.(type) {
	// TODO: case []byte: // ?
	case int64:
		*d = Duration(v)
	case float64:
		*d = Duration(int64(v))
	case nil:
		*d = Duration(0)
	default:
		return fmt.Errorf("cannot sql.Scan() strfmt.Duration from: %#v", v)
	}

	return nil
}

func
(
d
*
Duration
)
Scan
(
raw
interface
{
}
)
error
{
switch
v
:=
raw
.
(
type
)
{
// TODO: case []byte: // ?
case
int64
:
*
d
=
Duration
(
v
)
case
float64
:
*
d
=
Duration
(
int64
(
v
)
)
case
:
*
d
=
Duration
(
0
)
default
:
return
fmt
.
Errorf
(
"
"
,
v
)
}
return
}

// Scan reads a Duration value from database driver type.

Scan reads a Duration value from database driver type .


func (d Duration) Value() (driver.Value, error) {
	return driver.Value(int64(d)), nil
}

func ( d Duration ) Value ( ) ( driver . Value , error ) { return driver . Value ( int64 ( d ) ) , nil }

// Value converts Duration to a primitive value ready to be written to a database.

Value converts Duration to a primitive value ready to be written to a database .


func (d Duration) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	d.MarshalEasyJSON(&w)
	return w.BuildBytes()
}

func ( d Duration ) MarshalJSON ( ) ( [ ] byte , error ) { var w jwriter . Writer d . MarshalEasyJSON ( & w ) return w . BuildBytes ( ) }

// MarshalJSON returns the Duration as JSON


func (d Duration) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(time.Duration(d).String())
}

func ( d Duration ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( time . Duration ( d ) . String ( ) ) }

// MarshalEasyJSON writes the Duration to a easyjson.Writer

MarshalEasyJSON writes the Duration to a easyjson . Writer


func (d *Duration) UnmarshalJSON(data []byte) error {
	l := jlexer.Lexer{Data: data}
	d.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( d * Duration ) UnmarshalJSON ( data [ ] byte ) error { l := jlexer . Lexer { Data : data } d . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the Duration from JSON


func (d *Duration) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		tt, err := ParseDuration(data)
		if err != nil {
			in.AddError(err)
			return
		}
		*d = Duration(tt)
	}
}

func ( d * Duration ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { tt , err := ParseDuration ( data ) if err != nil { in . AddError ( err ) return } * d = Duration ( tt ) } }

// UnmarshalEasyJSON sets the Duration from a easyjson.Lexer

UnmarshalEasyJSON sets the Duration from a easyjson . Lexer


func (d *Duration) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(int64); ok {
		*d = Duration(data)
		return nil
	}

	return errors.New("couldn't unmarshal bson raw value as Duration")
}

func ( d * Duration ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( int64 ) ; ok { * d = Duration ( data ) return nil } return errors . New ( " " ) }

// SetBSON sets the Duration from raw bson data


func (d *Duration) DeepCopy() *Duration {
	if d == nil {
		return nil
	}
	out := new(Duration)
	d.DeepCopyInto(out)
	return out
}

func ( d * Duration ) DeepCopy ( ) * Duration { if d == nil { return nil } out := new ( Duration ) d . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new Duration.

DeepCopy copies the receiver into a new Duration .


func DateValue(v *strfmt.Date) strfmt.Date {
	if v == nil {
		return strfmt.Date{}
	}

	return *v
}

func DateValue ( v * strfmt . Date ) strfmt . Date { if v == nil { return strfmt . Date { } } return * v }

// DateValue returns the value of the Date pointer passed in or
// the default value if the pointer is nil.

DateValue returns the value of the Date pointer passed in or the default value if the pointer is nil .


func IsDate(str string) bool {
	_, err := time.Parse(RFC3339FullDate, str)
	return err == nil
}

func IsDate ( str string ) bool { _ , err := time . Parse ( RFC3339FullDate , str ) return err == nil }

// IsDate returns true when the string is a valid date


func (d *Date) UnmarshalText(text []byte) error {
	if len(text) == 0 {
		return nil
	}
	dd, err := time.Parse(RFC3339FullDate, string(text))
	if err != nil {
		return err
	}
	*d = Date(dd)
	return nil
}

func ( d * Date ) UnmarshalText ( text [ ] byte ) error { if len ( text ) == 0 { return nil } dd , err := time . Parse ( RFC3339FullDate , string ( text ) ) if err != nil { return err } * d = Date ( dd ) return nil }

// UnmarshalText parses a text representation into a date type


func (d *Date) Scan(raw interface{}) error {
	switch v := raw.(type) {
	case []byte:
		return d.UnmarshalText(v)
	case string:
		return d.UnmarshalText([]byte(v))
	case time.Time:
		*d = Date(v)
		return nil
	case nil:
		*d = Date{}
		return nil
	default:
		return fmt.Errorf("cannot sql.Scan() strfmt.Date from: %#v", v)
	}
}

func ( d * Date ) Scan ( raw interface { } ) error { switch v := raw . ( type ) { case [ ] byte : return d . UnmarshalText ( v ) case string : return d . UnmarshalText ( [ ] byte ( v ) ) case time . Time : * d = Date ( v ) return nil case nil : * d = Date { } return nil default : return fmt . Errorf ( " " , v ) } }

// Scan scans a Date value from database driver type.

Scan scans a Date value from database driver type .


func (d Date) Value() (driver.Value, error) {
	return driver.Value(d.String()), nil
}

func ( d Date ) Value ( ) ( driver . Value , error ) { return driver . Value ( d . String ( ) ) , nil }

// Value converts Date to a primitive value ready to written to a database.

Value converts Date to a primitive value ready to written to a database .


func (d Date) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(time.Time(d).Format(RFC3339FullDate))
}

func ( d Date ) MarshalEasyJSON ( w * jwriter . Writer ) { w . String ( time . Time ( d ) . Format ( RFC3339FullDate ) ) }

// MarshalEasyJSON writes the Date to a easyjson.Writer

MarshalEasyJSON writes the Date to a easyjson . Writer


func (d *Date) UnmarshalJSON(data []byte) error {
	if string(data) == jsonNull {
		return nil
	}
	l := jlexer.Lexer{Data: data}
	d.UnmarshalEasyJSON(&l)
	return l.Error()
}

func ( d * Date ) UnmarshalJSON ( data [ ] byte ) error { if string ( data ) == jsonNull { return nil } l := jlexer . Lexer { Data : data } d . UnmarshalEasyJSON ( & l ) return l . Error ( ) }

// UnmarshalJSON sets the Date from JSON


func (d *Date) UnmarshalEasyJSON(in *jlexer.Lexer) {
	if data := in.String(); in.Ok() {
		tt, err := time.Parse(RFC3339FullDate, data)
		if err != nil {
			in.AddError(err)
			return
		}
		*d = Date(tt)
	}
}

func ( d * Date ) UnmarshalEasyJSON ( in * jlexer . Lexer ) { if data := in . String ( ) ; in . Ok ( ) { tt , err := time . Parse ( RFC3339FullDate , data ) if err != nil { in . AddError ( err ) return } * d = Date ( tt ) } }

// UnmarshalEasyJSON sets the Date from a easyjson.Lexer

UnmarshalEasyJSON sets the Date from a easyjson . Lexer


func (d *Date) SetBSON(raw bson.Raw) error {
	var m bson.M
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}

	if data, ok := m["data"].(string); ok {
		rd, err := time.Parse(RFC3339FullDate, data)
		*d = Date(rd)
		return err
	}

	return errors.New("couldn't unmarshal bson raw value as Date")
}

func ( d * Date ) SetBSON ( raw bson . Raw ) error { var m bson . M if err := raw . Unmarshal ( & m ) ; err != nil { return err } if data , ok := m [ " " ] . ( string ) ; ok { rd , err := time . Parse ( RFC3339FullDate , data ) * d = Date ( rd ) return err } return errors . New ( " " ) }

// SetBSON sets the Date from raw bson data


func (d *Date) DeepCopy() *Date {
	if d == nil {
		return nil
	}
	out := new(Date)
	d.DeepCopyInto(out)
	return out
}

func ( d * Date ) DeepCopy ( ) * Date { if d == nil { return nil } out := new ( Date ) d . DeepCopyInto ( out ) return out }

// DeepCopy copies the receiver into a new Date.

DeepCopy copies the receiver into a new Date .


func DateTimeValue(v *strfmt.DateTime) strfmt.DateTime {
	if v == nil {
		return strfmt.DateTime{}
	}

	return *v
}

func DateTimeValue ( v * strfmt . DateTime ) strfmt . DateTime { if v == nil { return strfmt . DateTime { } } return * v }

// DateTimeValue returns the value of the DateTime pointer passed in or
// the default value if the pointer is nil.

DateTimeValue returns the value of the DateTime pointer passed in or the default value if the pointer is nil .


func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
	if normalizer == nil {
		normalizer = DefaultNameNormalizer
	}
	// copy here, don't modify original
	d := append([]knownFormat(nil), seeds...)
	return &defaultFormats{
		data:          d,
		normalizeName: normalizer,
	}
}

func
NewSeededFormats
(
seeds
[
]
knownFormat
,
normalizer
NameNormalizer
)
Registry
{
if
normalizer
==
{
normalizer
=
DefaultNameNormalizer
}
// copy here, don't modify original
d
:=
append
(
[
]
knownFormat
(
)
,
seeds
...
)
return
&
defaultFormats
{
data
:
d
,
normalizeName
:
normalizer
,
}
}

// NewSeededFormats creates a new formats registry


func (f *defaultFormats) Add(name string, strfmt Format, validator Validator) bool {
	f.Lock()
	defer f.Unlock()

	nme := f.normalizeName(name)

	tpe := reflect.TypeOf(strfmt)
	if tpe.Kind() == reflect.Ptr {
		tpe = tpe.Elem()
	}

	for i := range f.data {
		v := &f.data[i]
		if v.Name == nme {
			v.Type = tpe
			v.Validator = validator
			return false
		}
	}

	// turns out it's new after all
	f.data = append(f.data, knownFormat{Name: nme, OrigName: name, Type: tpe, Validator: validator})
	return true
}

func
(
f
*
defaultFormats
)
Add
(
name
string
,
strfmt
Format
,
validator
Validator
)
bool
{
f
.
Lock
(
)
defer
f
.
Unlock
(
)
nme
:=
f
.
normalizeName
(
name
)
tpe
:=
reflect
.
TypeOf
(
strfmt
)
if
tpe
.
Kind
(
)
==
reflect
.
Ptr
{
tpe
=
tpe
.
Elem
(
)
}
for
i
:=
range
f
.
data
{
v
:=
&
f
.
data
[
i
]
if
v
.
Name
==
nme
{
v
.
Type
=
tpe
v
.
Validator
=
validator
return
false
}
}
// turns out it's new after all
f
.
data
=
append
(
f
.
data
,
knownFormat
{
Name
:
nme
,
OrigName
:
name
,
Type
:
tpe
,
Validator
:
validator
}
)
return
true
}

// Add adds a new format, return true if this was a new item instead of a replacement

Add adds a new format return true if this was a new item instead of a replacement


func (f *defaultFormats) GetType(name string) (reflect.Type, bool) {
	f.Lock()
	defer f.Unlock()
	nme := f.normalizeName(name)
	for _, v := range f.data {
		if v.Name == nme {
			return v.Type, true
		}
	}
	return nil, false
}

func ( f * defaultFormats ) GetType ( name string ) ( reflect . Type , bool ) { f . Lock ( ) defer f . Unlock ( ) nme := f . normalizeName ( name ) for _ , v := range f . data { if v . Name == nme { return v . Type , true } } return nil , false }

// GetType gets the type for the specified name


func (f *defaultFormats) DelByName(name string) bool {
	f.Lock()
	defer f.Unlock()

	nme := f.normalizeName(name)

	for i, v := range f.data {
		if v.Name == nme {
			f.data[i] = knownFormat{} // release
			f.data = append(f.data[:i], f.data[i+1:]...)
			return true
		}
	}
	return false
}

func
(
f
*
defaultFormats
)
DelByName
(
name
string
)
bool
{
f
.
Lock
(
)
defer
f
.
Unlock
(
)
nme
:=
f
.
normalizeName
(
name
)
for
i
,
v
:=
range
f
.
data
{
if
v
.
Name
==
nme
{
f
.
data
[
i
]
=
knownFormat
{
}
// release
f
.
data
=
append
(
f
.
data
[
:
i
]
,
f
.
data
[
i
+
1
:
]
...
)
return
true
}
}
return
false
}

// DelByName removes the format by the specified name, returns true when an item was actually removed

DelByName removes the format by the specified name returns true when an item was actually removed


func (f *defaultFormats) DelByFormat(strfmt Format) bool {
	f.Lock()
	defer f.Unlock()

	tpe := reflect.TypeOf(strfmt)
	if tpe.Kind() == reflect.Ptr {
		tpe = tpe.Elem()
	}

	for i, v := range f.data {
		if v.Type == tpe {
			f.data[i] = knownFormat{} // release
			f.data = append(f.data[:i], f.data[i+1:]...)
			return true
		}
	}
	return false
}

func
(
f
*
defaultFormats
)
DelByFormat
(
strfmt
Format
)
bool
{
f
.
Lock
(
)
defer
f
.
Unlock
(
)
tpe
:=
reflect
.
TypeOf
(
strfmt
)
if
tpe
.
Kind
(
)
==
reflect
.
Ptr
{
tpe
=
tpe
.
Elem
(
)
}
for
i
,
v
:=
range
f
.
data
{
if
v
.
Type
==
tpe
{
f
.
data
[
i
]
=
knownFormat
{
}
// release
f
.
data
=
append
(
f
.
data
[
:
i
]
,
f
.
data
[
i
+
1
:
]
...
)
return
true
}
}
return
false
}

// DelByType removes the specified format, returns true when an item was actually removed

DelByType removes the specified format returns true when an item was actually removed


func (f *defaultFormats) ContainsName(name string) bool {
	f.Lock()
	defer f.Unlock()
	nme := f.normalizeName(name)
	for _, v := range f.data {
		if v.Name == nme {
			return true
		}
	}
	return false
}

func ( f * defaultFormats ) ContainsName ( name string ) bool { f . Lock ( ) defer f . Unlock ( ) nme := f . normalizeName ( name ) for _ , v := range f . data { if v . Name == nme { return true } } return false }

// ContainsName returns true if this registry contains the specified name


func (f *defaultFormats) ContainsFormat(strfmt Format) bool {
	f.Lock()
	defer f.Unlock()
	tpe := reflect.TypeOf(strfmt)
	if tpe.Kind() == reflect.Ptr {
		tpe = tpe.Elem()
	}

	for _, v := range f.data {
		if v.Type == tpe {
			return true
		}
	}
	return false
}

func ( f * defaultFormats ) ContainsFormat ( strfmt Format ) bool { f . Lock ( ) defer f . Unlock ( ) tpe := reflect . TypeOf ( strfmt ) if tpe . Kind ( ) == reflect . Ptr { tpe = tpe . Elem ( ) } for _ , v := range f . data { if v . Type == tpe { return true } } return false }

// ContainsFormat returns true if this registry contains the specified format


func (f *defaultFormats) Parse(name, data string) (interface{}, error) {
	f.Lock()
	defer f.Unlock()
	nme := f.normalizeName(name)
	for _, v := range f.data {
		if v.Name == nme {
			nw := reflect.New(v.Type).Interface()
			if dec, ok := nw.(encoding.TextUnmarshaler); ok {
				if err := dec.UnmarshalText([]byte(data)); err != nil {
					return nil, err
				}
				return nw, nil
			}
			return nil, errors.InvalidTypeName(name)
		}
	}
	return nil, errors.InvalidTypeName(name)
}

func ( f * defaultFormats ) Parse ( name , data string ) ( interface { } , error ) { f . Lock ( ) defer f . Unlock ( ) nme := f . normalizeName ( name ) for _ , v := range f . data { if v . Name == nme { nw := reflect . New ( v . Type ) . Interface ( ) if dec , ok := nw . ( encoding . TextUnmarshaler ) ; ok { if err := dec . UnmarshalText ( [ ] byte ( data ) ) ; err != nil { return nil , err } return nw , nil } return nil , errors . InvalidTypeName ( name ) } } return nil , errors . InvalidTypeName ( name ) }

// Parse a string into the appropriate format representation type.
//
// E.g. parsing a string a "date" will return a Date type.

Parse a string into the appropriate format representation type . E . g . parsing a string a date will return a Date type .


func Sequence(filters ...Filter) Filter {
	if len(filters) == 1 {
		return filters[0]
	}
	return FilterFunc(func(arg Arg) error {
		e := &filterErrors{}
		in := arg.In
		for _, f := range filters {
			c := make(chan string, channelBuffer)
			go runFilter(f, Arg{In: in, Out: c}, e)
			in = c
		}
		for s := range in {
			arg.Out <- s
		}
		return e.getError()
	})
}

func Sequence ( filters ... Filter ) Filter { if len ( filters ) == 1 { return filters [ 0 ] } return FilterFunc ( func ( arg Arg ) error { e := & filterErrors { } in := arg . In for _ , f := range filters { c := make ( chan string , channelBuffer ) go runFilter ( f , Arg { In : in , Out : c } , e ) in = c } for s := range in { arg . Out <- s } return e . getError ( ) } ) }

// Sequence returns a filter that is the concatenation of all filter arguments.
// The output of a filter is fed as input to the next filter.

Sequence returns a filter that is the concatenation of all filter arguments . The output of a filter is fed as input to the next filter .


func Contents(filters ...Filter) ([]string, error) {
	var result []string
	err := ForEach(Sequence(filters...), func(s string) {
		result = append(result, s)
	})
	if err != nil {
		result = nil // Discard results on error
	}
	return result, err
}

func
Contents
(
filters
...
Filter
)
(
[
]
string
,
error
)
{
var
result
[
]
string
err
:=
ForEach
(
Sequence
(
filters
...
)
,
func
(
s
string
)
{
result
=
append
(
result
,
s
)
}
)
if
err
!=
{
result
=
// Discard results on error
}
return
result
,
err
}

// Contents returns a slice that contains all items that are
// the output of filters.

Contents returns a slice that contains all items that are the output of filters .


func Items(items ...string) Filter {
	return FilterFunc(func(arg Arg) error {
		for _, s := range items {
			arg.Out <- s
		}
		return nil
	})
}

func Items ( items ... string ) Filter { return FilterFunc ( func ( arg Arg ) error { for _ , s := range items { arg . Out <- s } return nil } ) }


func Repeat(s string, n int) Filter {
	return FilterFunc(func(arg Arg) error {
		for i := 0; i < n; i++ {
			arg.Out <- s
		}
		return nil
	})
}

func Repeat ( s string , n int ) Filter { return FilterFunc ( func ( arg Arg ) error { for i := 0 ; i < n ; i ++ { arg . Out <- s } return nil } ) }


func Numbers(x, y int) Filter {
	return FilterFunc(func(arg Arg) error {
		for i := x; i <= y; i++ {
			arg.Out <- fmt.Sprint(i)
		}
		return nil
	})
}

func Numbers ( x , y int ) Filter { return FilterFunc ( func ( arg Arg ) error { for i := x ; i <= y ; i ++ { arg . Out <- fmt . Sprint ( i ) } return nil } ) }


func Uniq() Filter {
	return FilterFunc(func(arg Arg) error {
		first := true
		last := ""
		for s := range arg.In {
			if first || last != s {
				arg.Out <- s
			}
			last = s
			first = false
		}
		return nil
	})
}

func Uniq ( ) Filter { return FilterFunc ( func ( arg Arg ) error { first := true last := " " for s := range arg . In { if first || last != s { arg . Out <- s } last = s first = false } return nil } ) }

// Uniq squashes adjacent identical items in arg.In into a single output.

Uniq squashes adjacent identical items in arg . In into a single output .


func UniqWithCount() Filter {
	return FilterFunc(func(arg Arg) error {
		current := ""
		count := 0
		for s := range arg.In {
			if s != current {
				if count > 0 {
					arg.Out <- fmt.Sprintf("%d %s", count, current)
				}
				count = 0
				current = s
			}
			count++
		}
		if count > 0 {
			arg.Out <- fmt.Sprintf("%d %s", count, current)
		}
		return nil
	})
}

func UniqWithCount ( ) Filter { return FilterFunc ( func ( arg Arg ) error { current := " " count := 0 for s := range arg . In { if s != current { if count > 0 { arg . Out <- fmt . Sprintf ( " " , count , current ) } count = 0 current = s } count ++ } if count > 0 { arg . Out <- fmt . Sprintf ( " " , count , current ) } return nil } ) }

// UniqWithCount squashes adjacent identical items in arg.In into a single
// output prefixed with the count of identical items followed by a space.

UniqWithCount squashes adjacent identical items in arg . In into a single output prefixed with the count of identical items followed by a space .


func Reverse() Filter {
	return FilterFunc(func(arg Arg) error {
		var data []string
		for s := range arg.In {
			data = append(data, s)
		}
		for i := len(data) - 1; i >= 0; i-- {
			arg.Out <- data[i]
		}
		return nil
	})
}

func Reverse ( ) Filter { return FilterFunc ( func ( arg Arg ) error { var data [ ] string for s := range arg . In { data = append ( data , s ) } for i := len ( data ) - 1 ; i >= 0 ; i -- { arg . Out <- data [ i ] } return nil } ) }

// Reverse yields items in the reverse of the order it received them.

Reverse yields items in the reverse of the order it received them .


func SampleWithSeed(n int, seed int64) Filter {
	return FilterFunc(func(arg Arg) error {
		// Could speed this up by using Algorithm Z from Vitter.
		r := rand.New(rand.NewSource(seed))
		reservoir := make([]string, 0, n)
		i := 0
		for s := range arg.In {
			if i < n {
				reservoir = append(reservoir, s)
			} else {
				j := r.Intn(i + 1)
				if j < n {
					reservoir[j] = s
				}
			}
			i++
		}
		for _, s := range reservoir {
			arg.Out <- s
		}
		return nil
	})
}

// SampleWithSeed picks n pseudo-randomly chosen input items. It uses
// seed as the argument for its random number generation and therefore
// different executions of SampleWithSeed with the same arguments will
// chose the same items.

SampleWithSeed picks n pseudo - randomly chosen input items . It uses seed as the argument for its random number generation and therefore different executions of SampleWithSeed with the same arguments will chose the same items .


func First(n int) Filter {
	return FilterFunc(func(arg Arg) error {
		seen := 0
		for s := range arg.In {
			if seen >= n {
				break
			}
			arg.Out <- s
			seen++
		}
		return nil
	})
}

func First ( n int ) Filter { return FilterFunc ( func ( arg Arg ) error { seen := 0 for s := range arg . In { if seen >= n { break } arg . Out <- s seen ++ } return nil } ) }

// First yields the first n items that it receives.

First yields the first n items that it receives .


func Last(n int) Filter {
	return FilterFunc(func(arg Arg) error {
		r := newRing(n)
		for s := range arg.In {
			r.pushBack(s)
		}
		for !r.empty() {
			arg.Out <- r.popFront()
		}
		return nil
	})
}

func Last ( n int ) Filter { return FilterFunc ( func ( arg Arg ) error { r := newRing ( n ) for s := range arg . In { r . pushBack ( s ) } for ! r . empty ( ) { arg . Out <- r . popFront ( ) } return nil } ) }

// Last yields the last n items that it receives.

Last yields the last n items that it receives .


func DropLast(n int) Filter {
	return FilterFunc(func(arg Arg) error {
		r := newRing(n)
		for s := range arg.In {
			if r.full() {
				arg.Out <- r.popFront()
			}
			r.pushBack(s)
		}
		return nil
	})
}

func DropLast ( n int ) Filter { return FilterFunc ( func ( arg Arg ) error { r := newRing ( n ) for s := range arg . In { if r . full ( ) { arg . Out <- r . popFront ( ) } r . pushBack ( s ) } return nil } ) }

// DropLast yields all items except for the last n items that it receives.

DropLast yields all items except for the last n items that it receives .


func (s *SortFilter) Text(n int) *SortFilter {
	s.add(func(a, b string) int {
		a1, a2 := column(a, n)
		b1, b2 := column(b, n)
		switch {
		case a1 < b1:
			return -1
		case a1 > b1:
			return +1
		case a2 < b2:
			return -1
		case a2 > b2:
			return +1
		}
		return 0
	})
	return s
}

func ( s * SortFilter ) Text ( n int ) * SortFilter { s . add ( func ( a , b string ) int { a1 , a2 := column ( a , n ) b1 , b2 := column ( b , n ) switch { case a1 < b1 : return - 1 case a1 > b1 : return + 1 case a2 < b2 : return - 1 case a2 > b2 : return + 1 } return 0 } ) return s }

// Text sets the next sort key to sort by column n in lexicographic
// order. Column 0 means the entire string. Items that do not have
// column n sort to the front.

Text sets the next sort key to sort by column n in lexicographic order . Column 0 means the entire string . Items that do not have column n sort to the front .


func (s *SortFilter) TextDecreasing(n int) *SortFilter {
	return s.Text(n).flipLast()
}

func ( s * SortFilter ) TextDecreasing ( n int ) * SortFilter { return s . Text ( n ) . flipLast ( ) }

// TextDecreasing sets the next sort key to sort by column n in
// reverse lexicographic order. Column 0 means the entire
// string. Items that do not have column n sort to the end.

TextDecreasing sets the next sort key to sort by column n in reverse lexicographic order . Column 0 means the entire string . Items that do not have column n sort to the end .


func (s *SortFilter) Num(n int) *SortFilter {
	s.add(func(a, b string) int {
		a1, a2 := column(a, n)
		b1, b2 := column(b, n)
		switch {
		case a1 < b1:
			return -1
		case a1 > b1:
			return +1
		}

		// Convert columns from strings to numbers.
		a3, a4 := strconv.ParseFloat(a2, 64)
		b3, b4 := strconv.ParseFloat(b2, 64)

		if a4 != b4 {
			// Errors sort after numbers.
			if a4 != nil { // a had a parse error, b did not
				return +1
			}
			// b had a parse error, a did not
			return -1
		}

		switch {
		case a3 < b3:
			return -1
		case a3 > b3:
			return +1
		}
		return 0
	})
	return s
}

// Num sets the next sort key to sort by column n in numeric
// order. Column 0 means the entire string. Items that do not have
// column n sort to the front.  Items whose column n is not a number
// sort to the end.

Num sets the next sort key to sort by column n in numeric order . Column 0 means the entire string . Items that do not have column n sort to the front . Items whose column n is not a number sort to the end .


func (s *SortFilter) NumDecreasing(n int) *SortFilter {
	return s.Num(n).flipLast()
}

func ( s * SortFilter ) NumDecreasing ( n int ) * SortFilter { return s . Num ( n ) . flipLast ( ) }

// NumDecreasing sets the next sort key to sort by column n in reverse
// numeric order. Column 0 means the entire string. Items that do not
// have column n sort to the end.  Items whose column n is not a
// number sort to the front.

NumDecreasing sets the next sort key to sort by column n in reverse numeric order . Column 0 means the entire string . Items that do not have column n sort to the end . Items whose column n is not a number sort to the front .


func (s *SortFilter) By(less func(a, b string) bool) *SortFilter {
	s.add(func(a, b string) int {
		if less(a, b) {
			return -1
		}
		if less(b, a) {
			return +1
		}
		return 0
	})
	return s
}

func ( s * SortFilter ) By ( less func ( a , b string ) bool ) * SortFilter { s . add ( func ( a , b string ) int { if less ( a , b ) { return - 1 } if less ( b , a ) { return + 1 } return 0 } ) return s }

// By adds a sort key to sort by the output of the specified less function.

By adds a sort key to sort by the output of the specified less function .


func (s *SortFilter) flipLast() *SortFilter {
	last := s.cmp[len(s.cmp)-1]
	s.cmp[len(s.cmp)-1] = func(a, b string) int { return last(b, a) }
	return s
}

func ( s * SortFilter ) flipLast ( ) * SortFilter { last := s . cmp [ len ( s . cmp ) - 1 ] s . cmp [ len ( s . cmp ) - 1 ] = func ( a , b string ) int { return last ( b , a ) } return s }

// flipLast reverses the comparison order for the last sort key.

flipLast reverses the comparison order for the last sort key .


func (s *SortFilter) RunFilter(arg Arg) error {
	state := sortState{s.cmp, nil}
	for item := range arg.In {
		state.data = append(state.data, item)
	}
	sort.Sort(state)
	for _, item := range state.data {
		arg.Out <- item
	}
	return nil
}

func ( s * SortFilter ) RunFilter ( arg Arg ) error { state := sortState { s . cmp , nil } for item := range arg . In { state . data = append ( state . data , item ) } sort . Sort ( state ) for _ , item := range state . data { arg . Out <- item } return nil }

// RunFilter sorts items by the specified sorting keys. It implements
// the Filter interface.

RunFilter sorts items by the specified sorting keys . It implements the Filter interface .


func (f *FindFilter) RunFilter(arg Arg) error {
	return filepath.Walk(f.dir, func(n string, s os.FileInfo, e error) error {
		if e != nil {
			return e
		}
		if s.Mode().IsDir() && f.skipdirif(n) {
			return filepath.SkipDir
		}
		if f.ifmode(s.Mode()) {
			arg.Out <- n
		}
		return nil
	})
}

func ( f * FindFilter ) RunFilter ( arg Arg ) error { return filepath . Walk ( f . dir , func ( n string , s os . FileInfo , e error ) error { if e != nil { return e } if s . Mode ( ) . IsDir ( ) && f . skipdirif ( n ) { return filepath . SkipDir } if f . ifmode ( s . Mode ( ) ) { arg . Out <- n } return nil } ) }

// RunFilter yields contents of a filesystem tree. It implements the
// Filter interface.

RunFilter yields contents of a filesystem tree . It implements the Filter interface .


func Grep(r string) Filter {
	re, err := regexp.Compile(r)
	if err != nil {
		return FilterFunc(func(Arg) error { return err })
	}
	return If(re.MatchString)
}

func Grep ( r string ) Filter { re , err := regexp . Compile ( r ) if err != nil { return FilterFunc ( func ( Arg ) error { return err } ) } return If ( re . MatchString ) }

// Grep emits every input x that matches the regular expression r.

Grep emits every input x that matches the regular expression r .


func GrepNot(r string) Filter {
	re, err := regexp.Compile(r)
	if err != nil {
		return FilterFunc(func(Arg) error { return err })
	}
	return If(func(s string) bool { return !re.MatchString(s) })
}

func GrepNot ( r string ) Filter { re , err := regexp . Compile ( r ) if err != nil { return FilterFunc ( func ( Arg ) error { return err } ) } return If ( func ( s string ) bool { return ! re . MatchString ( s ) } ) }

// GrepNot emits every input x that does not match the regular expression r.

GrepNot emits every input x that does not match the regular expression r .


func (x *XargsFilter) LimitArgs(n int) *XargsFilter {
	x.limitArgs = n
	return x
}

func ( x * XargsFilter ) LimitArgs ( n int ) * XargsFilter { x . limitArgs = n return x }

// LimitArgs adjusts x so that no more than n input items are passed to
// a single command execution.  If not called, an unspecified number
// of input items may be handled via a single command execution.

LimitArgs adjusts x so that no more than n input items are passed to a single command execution . If not called an unspecified number of input items may be handled via a single command execution .


func Cat(filenames ...string) Filter {
	return FilterFunc(func(arg Arg) error {
		if len(filenames) == 0 {
			for s := range arg.In {
				arg.Out <- s
			}
			return nil
		}
		for _, f := range filenames {
			file, err := os.Open(f)
			if err == nil {
				err = splitIntoLines(file, arg)
				file.Close()
			}
			if err != nil {
				return err
			}
		}
		return nil
	})
}

func Cat ( filenames ... string ) Filter { return FilterFunc ( func ( arg Arg ) error { if len ( filenames ) == 0 { for s := range arg . In { arg . Out <- s } return nil } for _ , f := range filenames { file , err := os . Open ( f ) if err == nil { err = splitIntoLines ( file , arg ) file . Close ( ) } if err != nil { return err } } return nil } ) }

// Cat emits each line from each named file in order. If no arguments
// are specified, Cat copies its input to its output.

Cat emits each line from each named file in order . If no arguments are specified Cat copies its input to its output .


func ReadLines(reader io.Reader) Filter {
	return FilterFunc(func(arg Arg) error {
		return splitIntoLines(reader, arg)
	})
}

func ReadLines ( reader io . Reader ) Filter { return FilterFunc ( func ( arg Arg ) error { return splitIntoLines ( reader , arg ) } ) }

// ReadLines emits each line found in reader.

ReadLines emits each line found in reader .


func (l HostsLine) IsComment() bool {
	trimLine := strings.TrimSpace(l.Raw)
	isComment := strings.HasPrefix(trimLine, commentChar)
	return isComment
}

func ( l HostsLine ) IsComment ( ) bool { trimLine := strings . TrimSpace ( l . Raw ) isComment := strings . HasPrefix ( trimLine , commentChar ) return isComment }

// Return ```true``` if the line is a comment.


func NewHostsLine(raw string) HostsLine {
	fields := strings.Fields(raw)
	if len(fields) == 0 {
		return HostsLine{Raw: raw}
	}

	output := HostsLine{Raw: raw}
	if !output.IsComment() {
		rawIP := fields[0]
		if net.ParseIP(rawIP) == nil {
			output.Err = errors.New(fmt.Sprintf("Bad hosts line: %q", raw))
		}

		output.IP = rawIP
		output.Hosts = fields[1:]
	}

	return output
}

func NewHostsLine ( raw string ) HostsLine { fields := strings . Fields ( raw ) if len ( fields ) == 0 { return HostsLine { Raw : raw } } output := HostsLine { Raw : raw } if ! output . IsComment ( ) { rawIP := fields [ 0 ] if net . ParseIP ( rawIP ) == nil { output . Err = errors . New ( fmt . Sprintf ( " " , raw ) ) } output . IP = rawIP output . Hosts = fields [ 1 : ] } return output }

// Return a new instance of ```HostsLine```.


func (h *Hosts) IsWritable() bool {
	_, err := os.OpenFile(h.Path, os.O_WRONLY, 0660)
	if err != nil {
		return false
	}

	return true
}

func ( h * Hosts ) IsWritable ( ) bool { _ , err := os . OpenFile ( h . Path , os . O_WRONLY , 0660 ) if err != nil { return false } return true }

// Return ```true``` if hosts file is writable.


func (h Hosts) Flush() error {
	file, err := os.Create(h.Path)
	if err != nil {
		return err
	}

	w := bufio.NewWriter(file)

	for _, line := range h.Lines {
		fmt.Fprintf(w, "%s%s", line.Raw, eol)
	}

	err = w.Flush()
	if err != nil {
		return err
	}

	return h.Load()
}

func ( h Hosts ) Flush ( ) error { file , err := os . Create ( h . Path ) if err != nil { return err } w := bufio . NewWriter ( file ) for _ , line := range h . Lines { fmt . Fprintf ( w , " " , line . Raw , eol ) } err = w . Flush ( ) if err != nil { return err } return h . Load ( ) }

// Flush any changes made to hosts file.


func (h *Hosts) Add(ip string, hosts ...string) error {
	if net.ParseIP(ip) == nil {
		return errors.New(fmt.Sprintf("%q is an invalid IP address.", ip))
	}

	position := h.getIpPosition(ip)
	if position == -1 {
		endLine := NewHostsLine(buildRawLine(ip, hosts))
		// Ip line is not in file, so we just append our new line.
		h.Lines = append(h.Lines, endLine)
	} else {
		// Otherwise, we replace the line in the correct position
		newHosts := h.Lines[position].Hosts
		for _, addHost := range hosts {
			if itemInSlice(addHost, newHosts) {
				continue
			}

			newHosts = append(newHosts, addHost)
		}
		endLine := NewHostsLine(buildRawLine(ip, newHosts))
		h.Lines[position] = endLine
	}

	return nil
}


func (h *Hosts) Remove(ip string, hosts ...string) error {
	var outputLines []HostsLine

	if net.ParseIP(ip) == nil {
		return errors.New(fmt.Sprintf("%q is an invalid IP address.", ip))
	}

	for _, line := range h.Lines {

		// Bad lines or comments just get readded.
		if line.Err != nil || line.IsComment() || line.IP != ip {
			outputLines = append(outputLines, line)
			continue
		}

		var newHosts []string
		for _, checkHost := range line.Hosts {
			if !itemInSlice(checkHost, hosts) {
				newHosts = append(newHosts, checkHost)
			}
		}

		// If hosts is empty, skip the line completely.
		if len(newHosts) > 0 {
			newLineRaw := line.IP

			for _, host := range newHosts {
				newLineRaw = fmt.Sprintf("%s %s", newLineRaw, host)
			}
			newLine := NewHostsLine(newLineRaw)
			outputLines = append(outputLines, newLine)
		}
	}

	h.Lines = outputLines
	return nil
}


func NewHosts() (Hosts, error) {
	osHostsFilePath := ""

	if os.Getenv("HOSTS_PATH") == "" {
		osHostsFilePath = os.ExpandEnv(filepath.FromSlash(hostsFilePath))
	} else {
		osHostsFilePath = os.Getenv("HOSTS_PATH")
	}

	hosts := Hosts{Path: osHostsFilePath}

	err := hosts.Load()
	if err != nil {
		return hosts, err
	}

	return hosts, nil
}

func NewHosts ( ) ( Hosts , error ) { osHostsFilePath := " " if os . Getenv ( " " ) == " " { osHostsFilePath = os . ExpandEnv ( filepath . FromSlash ( hostsFilePath ) ) } else { osHostsFilePath = os . Getenv ( " " ) } hosts := Hosts { Path : osHostsFilePath } err := hosts . Load ( ) if err != nil { return hosts , err } return hosts , nil }


func NewOpenAPISchemaFor(delegate discovery.OpenAPISchemaInterface, gvk schema.GroupVersionKind) (*OpenAPISchema, error) {
	log.Debugf("Fetching schema for %v", gvk)
	doc, err := delegate.OpenAPISchema()
	if err != nil {
		return nil, err
	}
	res, err := openapi.NewOpenAPIData(doc)
	if err != nil {
		return nil, err
	}

	sc := res.LookupResource(gvk)
	if sc == nil {
		gvr := schema.GroupResource{
			// TODO(mkm): figure out a meaningful group+resource for schemas.
			Group:    "schema",
			Resource: "schema",
		}
		return nil, errors.NewNotFound(gvr, fmt.Sprintf("%s", gvk))
	}
	return &OpenAPISchema{schema: sc}, nil
}

// NewOpenAPISchemaFor returns the OpenAPISchema object ready to validate objects of given GroupVersion


func (s *OpenAPISchema) Validate(obj *unstructured.Unstructured) []error {
	gvk := obj.GroupVersionKind()
	log.Infof("validate object %q", gvk)
	return validation.ValidateModel(obj.UnstructuredContent(), s.schema, fmt.Sprintf("%s.%s", gvk.Version, gvk.Kind))
}

func ( s * OpenAPISchema ) Validate ( obj * unstructured . Unstructured ) [ ] error { gvk := obj . GroupVersionKind ( ) log . Infof ( " " , gvk ) return validation . ValidateModel ( obj . UnstructuredContent ( ) , s . schema , fmt . Sprintf ( " " , gvk . Version , gvk . Kind ) ) }

// Validate is the primary entrypoint into this class


func FlattenToV1(objs []runtime.Object) []*unstructured.Unstructured {
	ret := make([]*unstructured.Unstructured, 0, len(objs))
	for _, obj := range objs {
		switch o := obj.(type) {
		case *unstructured.UnstructuredList:
			for i := range o.Items {
				ret = append(ret, &o.Items[i])
			}
		case *unstructured.Unstructured:
			ret = append(ret, o)
		default:
			panic("Unexpected unstructured object type")
		}
	}
	return ret
}

func FlattenToV1 ( objs [ ] runtime . Object ) [ ] * unstructured . Unstructured { ret := make ( [ ] * unstructured . Unstructured , 0 , len ( objs ) ) for _ , obj := range objs { switch o := obj . ( type ) { case * unstructured . UnstructuredList : for i := range o . Items { ret = append ( ret , & o . Items [ i ] ) } case * unstructured . Unstructured : ret = append ( ret , o ) default : panic ( " " ) } } return ret }

// FlattenToV1 expands any List-type objects into their members, and
// cooerces everything to v1.Unstructured.  Panics if coercion
// encounters an unexpected object type.

FlattenToV1 expands any List - type objects into their members and cooerces everything to v1 . Unstructured . Panics if coercion encounters an unexpected object type .


func ParseVersion(v *version.Info) (ServerVersion, error) {
	var ret ServerVersion
	var err error
	ret.Major, err = strconv.Atoi(v.Major)
	if err != nil {
		// Try to parse using GitVersion
		return parseGitVersion(v.GitVersion)
	}

	// trim "+" in minor version (happened on GKE)
	v.Minor = strings.TrimSuffix(v.Minor, "+")
	ret.Minor, err = strconv.Atoi(v.Minor)
	if err != nil {
		// Try to parse using GitVersion
		return parseGitVersion(v.GitVersion)
	}
	return ret, err
}

// ParseVersion parses version.Info into a ServerVersion struct

ParseVersion parses version . Info into a ServerVersion struct


func FetchVersion(v discovery.ServerVersionInterface) (ret ServerVersion, err error) {
	version, err := v.ServerVersion()
	if err != nil {
		return ServerVersion{}, err
	}
	return ParseVersion(version)
}

func FetchVersion ( v discovery . ServerVersionInterface ) ( ret ServerVersion , err error ) { version , err := v . ServerVersion ( ) if err != nil { return ServerVersion { } , err } return ParseVersion ( version ) }

// FetchVersion fetches version information from discovery client, and parses

FetchVersion fetches version information from discovery client and parses


func SetMetaDataAnnotation(obj metav1.Object, key, value string) {
	a := obj.GetAnnotations()
	if a == nil {
		a = make(map[string]string)
	}
	a[key] = value
	obj.SetAnnotations(a)
}

func SetMetaDataAnnotation ( obj metav1 . Object , key , value string ) { a := obj . GetAnnotations ( ) if a == nil { a = make ( map [ string ] string ) } a [ key ] = value obj . SetAnnotations ( a ) }

// SetMetaDataAnnotation sets an annotation value


func SetMetaDataLabel(obj metav1.Object, key, value string) {
	l := obj.GetLabels()
	if l == nil {
		l = make(map[string]string)
	}
	l[key] = value
	obj.SetLabels(l)
}

func SetMetaDataLabel ( obj metav1 . Object , key , value string ) { l := obj . GetLabels ( ) if l == nil { l = make ( map [ string ] string ) } l [ key ] = value obj . SetLabels ( l ) }

// SetMetaDataLabel sets an annotation value


func ResourceNameFor(mapper meta.RESTMapper, o runtime.Object) string {
	gvk := o.GetObjectKind().GroupVersionKind()
	mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
	if err != nil {
		log.Debugf("RESTMapper failed for %s: %s, falling back to kind", gvk, err)
		return strings.ToLower(gvk.Kind)
	}

	return mapping.Resource.Resource
}

func ResourceNameFor ( mapper meta . RESTMapper , o runtime . Object ) string { gvk := o . GetObjectKind ( ) . GroupVersionKind ( ) mapping , err := mapper . RESTMapping ( gvk . GroupKind ( ) , gvk . Version ) if err != nil { log . Debugf ( " " , gvk , err ) return strings . ToLower ( gvk . Kind ) } return mapping . Resource . Resource }

// ResourceNameFor returns a lowercase plural form of a type, for
// human messages.  Returns lowercased kind if discovery lookup fails.

ResourceNameFor returns a lowercase plural form of a type for human messages . Returns lowercased kind if discovery lookup fails .


func FqName(o metav1.Object) string {
	if o.GetNamespace() == "" {
		return o.GetName()
	}
	return fmt.Sprintf("%s.%s", o.GetNamespace(), o.GetName())
}

func FqName ( o metav1 . Object ) string { if o . GetNamespace ( ) == " " { return o . GetName ( ) } return fmt . Sprintf ( " " , o . GetNamespace ( ) , o . GetName ( ) ) }


func (n ImageName) String() string {
	buf := bytes.Buffer{}
	if n.Registry != "" {
		buf.WriteString(n.Registry)
		buf.WriteString("/")
	}
	if n.Repository != "" {
		buf.WriteString(n.Repository)
		buf.WriteString("/")
	}
	buf.WriteString(n.Name)
	if n.Digest != "" {
		buf.WriteString("@")
		buf.WriteString(n.Digest)
	} else {
		buf.WriteString(":")
		buf.WriteString(n.Tag)
	}
	return buf.String()
}

func ( n ImageName ) String ( ) string { buf := bytes . Buffer { } if n . Registry != " " { buf . WriteString ( n . Registry ) buf . WriteString ( " " ) } if n . Repository != " " { buf . WriteString ( n . Repository ) buf . WriteString ( " " ) } buf . WriteString ( n . Name ) if n . Digest != " " { buf . WriteString ( " " ) buf . WriteString ( n . Digest ) } else { buf . WriteString ( " " ) buf . WriteString ( n . Tag ) } return buf . String ( ) }

// String implements the Stringer interface


func (n ImageName) RegistryRepoName() string {
	repo := n.Repository
	if repo == "" {
		repo = "library"
	}
	return fmt.Sprintf("%s/%s", repo, n.Name)
}

func ( n ImageName ) RegistryRepoName ( ) string { repo := n . Repository if repo == " " { repo = " " } return fmt . Sprintf ( " " , repo , n . Name ) }

// RegistryRepoName returns the "repository" as used in the registry URL

RegistryRepoName returns the repository as used in the registry URL


func (n ImageName) RegistryURL() string {
	reg := n.Registry
	if reg == "" {
		reg = defaultRegistry
	}
	return fmt.Sprintf("https://%s", reg)
}

func ( n ImageName ) RegistryURL ( ) string { reg := n . Registry if reg == " " { reg = defaultRegistry } return fmt . Sprintf ( " " , reg ) }

// RegistryURL returns the deduced base URL of the registry for this image


func ParseImageName(image string) (ImageName, error) {
	ret := ImageName{}

	img, err := registry.ParseImage(image)
	if err != nil {
		return ret, err
	}

	ret.Registry = img.Domain
	ret.Name = img.Path
	ret.Digest = img.Digest.String()
	ret.Tag = img.Tag

	return ret, nil
}

func ParseImageName ( image string ) ( ImageName , error ) { ret := ImageName { } img , err := registry . ParseImage ( image ) if err != nil { return ret , err } ret . Registry = img . Domain ret . Name = img . Path ret . Digest = img . Digest . String ( ) ret . Tag = img . Tag return ret , nil }

// ParseImageName parses a docker image into an ImageName struct.

ParseImageName parses a docker image into an ImageName struct .


func NewRegistryResolver(opt registry.Opt) Resolver {
	return &registryResolver{
		opt:   opt,
		cache: make(map[string]string),
	}
}

func NewRegistryResolver ( opt registry . Opt ) Resolver { return & registryResolver { opt : opt , cache : make ( map [ string ] string ) , } }

// NewRegistryResolver returns a resolver that looks up a docker
// registry to resolve digests

NewRegistryResolver returns a resolver that looks up a docker registry to resolve digests


func NewLogFormatter(out io.Writer) log.Formatter {
	var ret = logFormatter{}
	if f, ok := out.(*os.File); ok {
		ret.colorise = terminal.IsTerminal(int(f.Fd()))
		ret.escapes = terminal.NewTerminal(f, "").Escape
	}
	return &ret
}

func NewLogFormatter ( out io . Writer ) log . Formatter { var ret = logFormatter { } if f , ok := out . ( * os . File ) ; ok { ret . colorise = terminal . IsTerminal ( int ( f . Fd ( ) ) ) ret . escapes = terminal . NewTerminal ( f , " " ) . Escape } return & ret }

// NewLogFormatter creates a new log.Formatter customised for writer

NewLogFormatter creates a new log . Formatter customised for writer


func NewMemcachedDiscoveryClient(cl discovery.DiscoveryInterface) discovery.CachedDiscoveryInterface {
	c := &memcachedDiscoveryClient{cl: cl}
	c.Invalidate()
	return c
}

func NewMemcachedDiscoveryClient ( cl discovery . DiscoveryInterface ) discovery . CachedDiscoveryInterface { c := & memcachedDiscoveryClient { cl : cl } c . Invalidate ( ) return c }

// NewMemcachedDiscoveryClient creates a new DiscoveryClient that
// caches results in memory

NewMemcachedDiscoveryClient creates a new DiscoveryClient that caches results in memory


func ClientForResource(client dynamic.Interface, mapper meta.RESTMapper, obj runtime.Object, defNs string) (dynamic.ResourceInterface, error) {
	gvk := obj.GetObjectKind().GroupVersionKind()

	mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
	if err != nil {
		return nil, err
	}

	rc := client.Resource(mapping.Resource)

	switch mapping.Scope.Name() {
	case meta.RESTScopeNameRoot:
		return rc, nil
	case meta.RESTScopeNameNamespace:
		meta, err := meta.Accessor(obj)
		if err != nil {
			return nil, err
		}
		namespace := meta.GetNamespace()
		if namespace == "" {
			namespace = defNs
		}
		return rc.Namespace(namespace), nil
	default:
		return nil, fmt.Errorf("unexpected resource scope %q", mapping.Scope)
	}
}

func ClientForResource ( client dynamic . Interface , mapper meta . RESTMapper , obj runtime . Object , defNs string ) ( dynamic . ResourceInterface , error ) { gvk := obj . GetObjectKind ( ) . GroupVersionKind ( ) mapping , err := mapper . RESTMapping ( gvk . GroupKind ( ) , gvk . Version ) if err != nil { return nil , err } rc := client . Resource ( mapping . Resource ) switch mapping . Scope . Name ( ) { case meta . RESTScopeNameRoot : return rc , nil case meta . RESTScopeNameNamespace : meta , err := meta . Accessor ( obj ) if err != nil { return nil , err } namespace := meta . GetNamespace ( ) if namespace == " " { namespace = defNs } return rc . Namespace ( namespace ) , nil default : return nil , fmt . Errorf ( " " , mapping . Scope ) } }

// ClientForResource returns the ResourceClient for a given object


func (c DiffCmd) formatDiff(diffs []diffmatchpatch.Diff, color bool) string {
	var buff bytes.Buffer

	for _, diff := range diffs {
		text := diff.Text

		switch diff.Type {
		case diffmatchpatch.DiffInsert:
			if color {
				_, _ = buff.WriteString("\x1b[32m")
			}
			_, _ = buff.WriteString(DiffLineStart.ReplaceAllString(text, "$1+ $2"))
			if color {
				_, _ = buff.WriteString("\x1b[0m")
			}
		case diffmatchpatch.DiffDelete:
			if color {
				_, _ = buff.WriteString("\x1b[31m")
			}
			_, _ = buff.WriteString(DiffLineStart.ReplaceAllString(text, "$1- $2"))
			if color {
				_, _ = buff.WriteString("\x1b[0m")
			}
		case diffmatchpatch.DiffEqual:
			_, _ = buff.WriteString(DiffLineStart.ReplaceAllString(text, "$1  $2"))
		}
	}

	return buff.String()
}

func ( c DiffCmd ) formatDiff ( diffs [ ] diffmatchpatch . Diff , color bool ) string { var buff bytes . Buffer for _ , diff := range diffs { text := diff . Text switch diff . Type { case diffmatchpatch . DiffInsert : if color { _ , _ = buff . WriteString ( " \x1b " ) } _ , _ = buff . WriteString ( DiffLineStart . ReplaceAllString ( text , " " ) ) if color { _ , _ = buff . WriteString ( " \x1b " ) } case diffmatchpatch . DiffDelete : if color { _ , _ = buff . WriteString ( " \x1b " ) } _ , _ = buff . WriteString ( DiffLineStart . ReplaceAllString ( text , " " ) ) if color { _ , _ = buff . WriteString ( " \x1b " ) } case diffmatchpatch . DiffEqual : _ , _ = buff . WriteString ( DiffLineStart . ReplaceAllString ( text , " " ) ) } } return buff . String ( ) }

// Formats the supplied Diff as a unified-diff-like text with infinite context and optionally colorizes it.

Formats the supplied Diff as a unified - diff - like text with infinite context and optionally colorizes it .


func isEmptyValue(i interface{}) bool {
	switch v := i.(type) {
	case []interface{}:
		return len(v) == 0
	case []string:
		return len(v) == 0
	case map[string]interface{}:
		return len(v) == 0
	case bool:
		return !v
	case float64:
		return v == 0
	case int64:
		return v == 0
	case string:
		return v == ""
	case nil:
		return true
	default:
		panic(fmt.Sprintf("Found unexpected type %T in json unmarshal (value=%v)", i, i))
	}
}

func isEmptyValue ( i interface { } ) bool { switch v := i . ( type ) { case [ ] interface { } : return len ( v ) == 0 case [ ] string : return len ( v ) == 0 case map [ string ] interface { } : return len ( v ) == 0 case bool : return ! v case float64 : return v == 0 case int64 : return v == 0 case string : return v == " " case nil : return true default : panic ( fmt . Sprintf ( " " , i , i ) ) } }

// See also feature request for golang reflect pkg at


func depTier(disco discovery.OpenAPISchemaInterface, mapper meta.RESTMapper, o schema.ObjectKind) (int, error) {
	gvk := o.GroupVersionKind()
	if gk := gvk.GroupKind(); gk == gkTpr || gk == gkCrd {
		// Special case: these create other types
		return 10, nil
	}

	mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
	if err != nil {
		log.Debugf("unable to fetch resource for %s (%v), continuing", gvk, err)
		return 50, nil
	}

	if mapping.Scope.Name() == meta.RESTScopeNameRoot {
		// Place global before namespaced
		return 20, nil
	} else if containsPodSpec(disco, gvk) {
		// (Potentially) starts a pod, so place last
		return 100, nil
	} else {
		// Everything else
		return 50, nil
	}
}

// Arbitrary numbers used to do a simple topological sort of resources.

Arbitrary numbers used to do a simple topological sort of resources .


func New(input string) *Lexer {
	l := &Lexer{input: input, curLine: 1}
	l.readChar()
	return l
}

func New ( input string ) * Lexer { l := & Lexer { input : input , curLine : 1 } l . readChar ( ) return l }


func (l *Lexer) NextToken() token.Token {
	if l.inside {
		return l.nextInsideToken()
	}
	var tok token.Token

	// l.skipWhitespace()
	if l.ch == 0 {
		tok.Literal = ""
		tok.Type = token.EOF
		tok.LineNumber = l.curLine
		return tok
	}

	if l.ch == '<' && l.peekChar() == '%' {
		l.inside = true
		return l.nextInsideToken()
	}

	tok.Type = token.HTML
	tok.Literal = l.readHTML()
	tok.LineNumber = l.curLine
	return tok
}

func
(
l
*
Lexer
)
NextToken
(
)
token
.
Token
{
if
l
.
inside
{
return
l
.
nextInsideToken
(
)
}
var
tok
token
.
Token
// l.skipWhitespace()
if
l
.
ch
==
0
{
tok
.
Literal
=
"
"
tok
.
Type
=
token
.
EOF
tok
.
LineNumber
=
l
.
curLine
return
tok
}
if
l
.
ch
==
'<'
&&
l
.
peekChar
(
)
==
'%'
{
l
.
inside
=
true
return
l
.
nextInsideToken
(
)
}
tok
.
Type
=
token
.
HTML
tok
.
Literal
=
l
.
readHTML
(
)
tok
.
LineNumber
=
l
.
curLine
return
tok
}


func (bs *BlockStatement) InnerText() string {
	var out bytes.Buffer
	for _, s := range bs.Statements {
		out.WriteString(s.String())
	}
	return out.String()
}

func ( bs * BlockStatement ) InnerText ( ) string { var out bytes . Buffer for _ , s := range bs . Statements { out . WriteString ( s . String ( ) ) } return out . String ( ) }

// InnerText gets the raw string representation of the block's contents.

InnerText gets the raw string representation of the block s contents .


func MarkdownHelper(body string, help HelperContext) (template.HTML, error) {
	var err error
	if help.HasBlock() {
		body, err = help.Block()
		if err != nil {
			return "", err
		}
	}
	b := github_flavored_markdown.Markdown([]byte(body))
	return template.HTML(b), err
}

func MarkdownHelper ( body string , help HelperContext ) ( template . HTML , error ) { var err error if help . HasBlock ( ) { body , err = help . Block ( ) if err != nil { return " " , err } } b := github_flavored_markdown . Markdown ( [ ] byte ( body ) ) return template . HTML ( b ) , err }

// Markdown converts the string into HTML using GitHub flavored markdown.

Markdown converts the string into HTML using GitHub flavored markdown .


func Parse(s string) (*ast.Program, error) {
	p := newParser(lexer.New(s))
	prog := p.parseProgram()
	if len(p.errors) > 0 {
		return prog, p.errors
	}
	return prog, nil
}

func Parse ( s string ) ( * ast . Program , error ) { p := newParser ( lexer . New ( s ) ) prog := p . parseProgram ( ) if len ( p . errors ) > 0 { return prog , p . errors } return prog , nil }

// Parse the string and return an AST or an error


func NewHelperMap() (HelperMap, error) {
	hm := HelperMap{
		helpers: map[string]interface{}{},
		moot:    &sync.Mutex{},
	}

	err := hm.AddMany(Helpers.Helpers())
	if err != nil {
		return hm, err
	}
	return hm, nil
}

func NewHelperMap ( ) ( HelperMap , error ) { hm := HelperMap { helpers : map [ string ] interface { } { } , moot : & sync . Mutex { } , } err := hm . AddMany ( Helpers . Helpers ( ) ) if err != nil { return hm , err } return hm , nil }

// NewHelperMap containing all of the "default" helpers from "plush.Helpers".

NewHelperMap containing all of the default helpers from plush . Helpers .


func (h *HelperMap) AddMany(helpers map[string]interface{}) error {
	for k, v := range helpers {
		err := h.Add(k, v)
		if err != nil {
			return err
		}
	}
	return nil
}

func ( h * HelperMap ) AddMany ( helpers map [ string ] interface { } ) error { for k , v := range helpers { err := h . Add ( k , v ) if err != nil { return err } } return nil }


func BuffaloRenderer(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error) {
	t, err := Parse(input)
	if err != nil {
		return "", err
	}
	if helpers != nil {
		for k, v := range helpers {
			data[k] = v
		}
	}
	return t.Exec(NewContextWith(data))
}

func BuffaloRenderer ( input string , data map [ string ] interface { } , helpers map [ string ] interface { } ) ( string , error ) { t , err := Parse ( input ) if err != nil { return " " , err } if helpers != nil { for k , v := range helpers { data [ k ] = v } } return t . Exec ( NewContextWith ( data ) ) }

// BuffaloRenderer implements the render.TemplateEngine interface allowing velvet to be used as a template engine
// for Buffalo

BuffaloRenderer implements the render . TemplateEngine interface allowing velvet to be used as a template engine for Buffalo


func Render(input string, ctx hctx.Context) (string, error) {
	t, err := Parse(input)
	if err != nil {
		return "", err
	}
	return t.Exec(ctx)
}

func Render ( input string , ctx hctx . Context ) ( string , error ) { t , err := Parse ( input ) if err != nil { return " " , err } return t . Exec ( ctx ) }

// Render a string using the given the context.

Render a string using the given the context .


func RunScript(input string, ctx hctx.Context) error {
	input = "<% " + input + "%>"

	ctx = ctx.New()
	ctx.Set("print", func(i interface{}) {
		fmt.Print(i)
	})
	ctx.Set("println", func(i interface{}) {
		fmt.Println(i)
	})

	_, err := Render(input, ctx)
	return err
}

func RunScript ( input string , ctx hctx . Context ) error { input = " " + input + " " ctx = ctx . New ( ) ctx . Set ( " " , func ( i interface { } ) { fmt . Print ( i ) } ) ctx . Set ( " " , func ( i interface { } ) { fmt . Println ( i ) } ) _ , err := Render ( input , ctx ) return err }

// RunScript allows for "pure" plush scripts to be executed.

RunScript allows for pure plush scripts to be executed .


func NewTemplate(input string) (*Template, error) {
	t := &Template{
		Input: input,
	}
	err := t.Parse()
	if err != nil {
		return t, err
	}
	return t, nil
}

func NewTemplate ( input string ) ( * Template , error ) { t := & Template { Input : input , } err := t . Parse ( ) if err != nil { return t , err } return t , nil }

// NewTemplate from the input string. Adds all of the
// global helper functions from "Helpers", this function does not
// cache the template.

NewTemplate from the input string . Adds all of the global helper functions from Helpers this function does not cache the template .


func (t *Template) Parse() error {
	if t.program != nil {
		return nil
	}
	program, err := parser.Parse(t.Input)
	if err != nil {
		return err
	}
	t.program = program
	return nil
}

func ( t * Template ) Parse ( ) error { if t . program != nil { return nil } program , err := parser . Parse ( t . Input ) if err != nil { return err } t . program = program return nil }

// Parse the template this can be called many times
// as a successful result is cached and is used on subsequent
// uses.

Parse the template this can be called many times as a successful result is cached and is used on subsequent uses .


func (t *Template) Exec(ctx hctx.Context) (string, error) {
	err := t.Parse()
	if err != nil {
		return "", err
	}

	ev := compiler{
		ctx:     ctx,
		program: t.program,
	}

	s, err := ev.compile()
	return s, err
}

func ( t * Template ) Exec ( ctx hctx . Context ) ( string , error ) { err := t . Parse ( ) if err != nil { return " " , err } ev := compiler { ctx : ctx , program : t . program , } s , err := ev . compile ( ) return s , err }

// Exec the template using the content and return the results


func (t *Template) Clone() *Template {
	t2 := &Template{
		Input:   t.Input,
		program: t.program,
	}
	return t2
}

func ( t * Template ) Clone ( ) * Template { t2 := & Template { Input : t . Input , program : t . program , } return t2 }

// Clone a template. This is useful for defining helpers on per "instance" of the template.

Clone a template . This is useful for defining helpers on per instance of the template .


func (h HelperContext) Render(s string) (string, error) {
	return Render(s, h.Context)
}

func ( h HelperContext ) Render ( s string ) ( string , error ) { return Render ( s , h . Context ) }

// Render a string with the current context


func (h HelperContext) BlockWith(hc hctx.Context) (string, error) {
	ctx, ok := hc.(*Context)
	if !ok {
		return "", fmt.Errorf("expected *Context, got %T", hc)
	}
	octx := h.compiler.ctx
	defer func() { h.compiler.ctx = octx }()
	h.compiler.ctx = ctx

	if h.block == nil {
		return "", errors.New("no block defined")
	}
	i, err := h.compiler.evalBlockStatement(h.block)
	if err != nil {
		return "", err
	}
	bb := &bytes.Buffer{}
	h.compiler.write(bb, i)
	return bb.String(), nil
}

func ( h HelperContext ) BlockWith ( hc hctx . Context ) ( string , error ) { ctx , ok := hc . ( * Context ) if ! ok { return " " , fmt . Errorf ( " " , hc ) } octx := h . compiler . ctx defer func ( ) { h . compiler . ctx = octx } ( ) h . compiler . ctx = ctx if h . block == nil { return " " , errors . New ( " " ) } i , err := h . compiler . evalBlockStatement ( h . block ) if err != nil { return " " , err } bb := & bytes . Buffer { } h . compiler . write ( bb , i ) return bb . String ( ) , nil }

// BlockWith executes the block of template associated with
// the helper, think the block inside of an "if" or "each"
// statement, but with it's own context.

BlockWith executes the block of template associated with the helper think the block inside of an if or each statement but with it s own context .


func (c *Context) Has(key string) bool {
	return c.Value(key) != nil
}

func ( c * Context ) Has ( key string ) bool { return c . Value ( key ) != nil }

// Has checks the existence of the key in the context.

Has checks the existence of the key in the context .


func (c *Context) export() map[string]interface{} {
	m := map[string]interface{}{}
	if c.outer != nil {
		for k, v := range c.outer.export() {
			m[k] = v
		}
	}
	for k, v := range c.data {
		m[k] = v
	}

	return m
}

func ( c * Context ) export ( ) map [ string ] interface { } { m := map [ string ] interface { } { } if c . outer != nil { for k , v := range c . outer . export ( ) { m [ k ] = v } } for k , v := range c . data { m [ k ] = v } return m }

// Export all the known values in the context.
// Note this can't reach up into other implemenations
// of context.Context.

Export all the known values in the context . Note this can t reach up into other implemenations of context . Context .


func NewContextWith(data map[string]interface{}) *Context {
	c := &Context{
		Context: context.Background(),
		data:    data,
		outer:   nil,
		moot:    &sync.Mutex{},
	}
	for k, v := range Helpers.helpers {
		if !c.Has(k) {
			c.Set(k, v)
		}
	}

	return c
}

func NewContextWith ( data map [ string ] interface { } ) * Context { c := & Context { Context : context . Background ( ) , data : data , outer : nil , moot : & sync . Mutex { } , } for k , v := range Helpers . helpers { if ! c . Has ( k ) { c . Set ( k , v ) } } return c }

// NewContextWith returns a fully formed context using the data
// provided.

NewContextWith returns a fully formed context using the data provided .


func NewContextWithContext(ctx context.Context) *Context {
	c := NewContext()
	c.Context = ctx
	return c
}

func NewContextWithContext ( ctx context . Context ) * Context { c := NewContext ( ) c . Context = ctx return c }

// NewContextWithContext returns a new plush.Context given another context

NewContextWithContext returns a new plush . Context given another context


func Aggregate(goroutines []*Goroutine, similar Similarity) []*Bucket {
	type count struct {
		ids   []int
		first bool
	}
	b := map[*Signature]*count{}
	// O(n²). Fix eventually.
	for _, routine := range goroutines {
		found := false
		for key, c := range b {
			// When a match is found, this effectively drops the other goroutine ID.
			if key.similar(&routine.Signature, similar) {
				found = true
				c.ids = append(c.ids, routine.ID)
				c.first = c.first || routine.First
				if !key.equal(&routine.Signature) {
					// Almost but not quite equal. There's different pointers passed
					// around but the same values. Zap out the different values.
					newKey := key.merge(&routine.Signature)
					b[newKey] = c
					delete(b, key)
				}
				break
			}
		}
		if !found {
			// Create a copy of the Signature, since it will be mutated.
			key := &Signature{}
			*key = routine.Signature
			b[key] = &count{ids: []int{routine.ID}, first: routine.First}
		}
	}
	out := make(buckets, 0, len(b))
	for signature, c := range b {
		sort.Ints(c.ids)
		out = append(out, &Bucket{Signature: *signature, IDs: c.ids, First: c.first})
	}
	sort.Sort(out)
	return out
}

// Aggregate merges similar goroutines into buckets.
//
// The buckets are ordered in library provided order of relevancy. You can
// reorder at your chosing.

Aggregate merges similar goroutines into buckets . The buckets are ordered in library provided order of relevancy . You can reorder at your chosing .


func (b *Bucket) less(r *Bucket) bool {
	if b.First || r.First {
		return b.First
	}
	return b.Signature.less(&r.Signature)
}

func ( b * Bucket ) less ( r * Bucket ) bool { if b . First || r . First { return b . First } return b . Signature . less ( & r . Signature ) }


func parseDump(r io.Reader, out io.Writer) ([]*Goroutine, error) {
	scanner := bufio.NewScanner(r)
	scanner.Split(scanLines)
	s := scanningState{}
	for scanner.Scan() {
		line, err := s.scan(scanner.Text())
		if line != "" {
			_, _ = io.WriteString(out, line)
		}
		if err != nil {
			return s.goroutines, err
		}
	}
	return s.goroutines, scanner.Err()
}

func parseDump ( r io . Reader , out io . Writer ) ( [ ] * Goroutine , error ) { scanner := bufio . NewScanner ( r ) scanner . Split ( scanLines ) s := scanningState { } for scanner . Scan ( ) { line , err := s . scan ( scanner . Text ( ) ) if line != " " { _ , _ = io . WriteString ( out , line ) } if err != nil { return s . goroutines , err } } return s . goroutines , scanner . Err ( ) }


func hasPathPrefix(p string, s map[string]string) bool {
	for prefix := range s {
		if strings.HasPrefix(p, prefix+"/") {
			return true
		}
	}
	return false
}

func hasPathPrefix ( p string , s map [ string ] string ) bool { for prefix := range s { if strings . HasPrefix ( p , prefix + " " ) { return true } } return false }

// hasPathPrefix returns true if any of s is the prefix of p.

hasPathPrefix returns true if any of s is the prefix of p .


func getFiles(goroutines []*Goroutine) []string {
	files := map[string]struct{}{}
	for _, g := range goroutines {
		for _, c := range g.Stack.Calls {
			files[c.SrcPath] = struct{}{}
		}
	}
	out := make([]string, 0, len(files))
	for f := range files {
		out = append(out, f)
	}
	sort.Strings(out)
	return out
}

func getFiles ( goroutines [ ] * Goroutine ) [ ] string { files := map [ string ] struct { } { } for _ , g := range goroutines { for _ , c := range g . Stack . Calls { files [ c . SrcPath ] = struct { } { } } } out := make ( [ ] string , 0 , len ( files ) ) for f := range files { out = append ( out , f ) } sort . Strings ( out ) return out }

// getFiles returns all the source files deduped and ordered.

getFiles returns all the source files deduped and ordered .


func splitPath(p string) []string {
	if p == "" {
		return nil
	}
	var out []string
	s := ""
	for _, c := range p {
		if c != '/' || (len(out) == 0 && strings.Count(s, "/") == len(s)) {
			s += string(c)
		} else if s != "" {
			out = append(out, s)
			s = ""
		}
	}
	if s != "" {
		out = append(out, s)
	}
	return out
}

func splitPath ( p string ) [ ] string { if p == " " { return nil } var out [ ] string s := " " for _ , c := range p { if c != '/' || ( len ( out ) == 0 && strings . Count ( s , " " ) == len ( s ) ) { s += string ( c ) } else if s != " " { out = append ( out , s ) s = " " } } if s != " " { out = append ( out , s ) } return out }

// splitPath splits a path into its components.
//
// The first item has its initial path separator kept.

splitPath splits a path into its components . The first item has its initial path separator kept .


func isFile(p string) bool {
	// TODO(maruel): Is it faster to open the file or to stat it? Worth a perf
	// test on Windows.
	i, err := os.Stat(p)
	return err == nil && !i.IsDir()
}

// isFile returns true if the path is a valid file.

isFile returns true if the path is a valid file .


func rootedIn(root string, parts []string) string {
	//log.Printf("rootIn(%s, %v)", root, parts)
	for i := 1; i < len(parts); i++ {
		suffix := filepath.Join(parts[i:]...)
		if isFile(filepath.Join(root, suffix)) {
			return filepath.Join(parts[:i]...)
		}
	}
	return ""
}

// rootedIn returns a root if the file split in parts is rooted in root.

rootedIn returns a root if the file split in parts is rooted in root .


func (c *Context) findRoots() {
	c.GOPATHs = map[string]string{}
	for _, f := range getFiles(c.Goroutines) {
		// TODO(maruel): Could a stack dump have mixed cases? I think it's
		// possible, need to confirm and handle.
		//log.Printf("  Analyzing %s", f)
		if c.GOROOT != "" && strings.HasPrefix(f, c.GOROOT+"/") {
			continue
		}
		if hasPathPrefix(f, c.GOPATHs) {
			continue
		}
		parts := splitPath(f)
		if c.GOROOT == "" {
			if r := rootedIn(c.localgoroot, parts); r != "" {
				c.GOROOT = r
				//log.Printf("Found GOROOT=%s", c.GOROOT)
				continue
			}
		}
		found := false
		for _, l := range c.localgopaths {
			if r := rootedIn(l, parts); r != "" {
				//log.Printf("Found GOPATH=%s", r)
				c.GOPATHs[r] = l
				found = true
				break
			}
		}
		if !found {
			// If the source is not found, just too bad.
			//log.Printf("Failed to find locally: %s / %s", f, goroot)
		}
	}
}

// findRoots sets member GOROOT and GOPATHs.

findRoots sets member GOROOT and GOPATHs .


func (f *Func) String() string {
	s, _ := url.QueryUnescape(f.Raw)
	return s
}

func ( f * Func ) String ( ) string { s , _ := url . QueryUnescape ( f . Raw ) return s }

// String is the fully qualified function name.
//
// Sadly Go is a bit confused when the package name doesn't match the directory
// containing the source file and will use the directory name instead of the
// real package name.

String is the fully qualified function name . Sadly Go is a bit confused when the package name doesn t match the directory containing the source file and will use the directory name instead of the real package name .


func (f *Func) Name() string {
	parts := strings.SplitN(filepath.Base(f.Raw), ".", 2)
	if len(parts) == 1 {
		return parts[0]
	}
	return parts[1]
}

func ( f * Func ) Name ( ) string { parts := strings . SplitN ( filepath . Base ( f . Raw ) , " " , 2 ) if len ( parts ) == 1 { return parts [ 0 ] } return parts [ 1 ] }


func (f *Func) PkgName() string {
	parts := strings.SplitN(filepath.Base(f.Raw), ".", 2)
	if len(parts) == 1 {
		return ""
	}
	s, _ := url.QueryUnescape(parts[0])
	return s
}

func ( f * Func ) PkgName ( ) string { parts := strings . SplitN ( filepath . Base ( f . Raw ) , " " , 2 ) if len ( parts ) == 1 { return " " } s , _ := url . QueryUnescape ( parts [ 0 ] ) return s }

// PkgName is the package name for this function reference.

PkgName is the package name for this function reference .


func (f *Func) IsExported() bool {
	name := f.Name()
	parts := strings.Split(name, ".")
	r, _ := utf8.DecodeRuneInString(parts[len(parts)-1])
	if unicode.ToUpper(r) == r {
		return true
	}
	return f.PkgName() == "main" && name == "main"
}

func ( f * Func ) IsExported ( ) bool { name := f . Name ( ) parts := strings . Split ( name , " " ) r , _ := utf8 . DecodeRuneInString ( parts [ len ( parts ) - 1 ] ) if unicode . ToUpper ( r ) == r { return true } return f . PkgName ( ) == " " && name == " " }

// IsExported returns true if the function is exported.

IsExported returns true if the function is exported .


func (a *Arg) IsPtr() bool {
	// Assumes all pointers are above 16Mb and positive.
	return a.Value > 16*1024*1024 && a.Value < math.MaxInt64
}

// IsPtr returns true if we guess it's a pointer. It's only a guess, it can be
// easily be confused by a bitmask.

IsPtr returns true if we guess it s a pointer . It s only a guess it can be easily be confused by a bitmask .


func (a *Args) equal(r *Args) bool {
	if a.Elided != r.Elided || len(a.Values) != len(r.Values) {
		return false
	}
	for i, l := range a.Values {
		if l != r.Values[i] {
			return false
		}
	}
	return true
}

func ( a * Args ) equal ( r * Args ) bool { if a . Elided != r . Elided || len ( a . Values ) != len ( r . Values ) { return false } for i , l := range a . Values { if l != r . Values [ i ] { return false } } return true }

// equal returns true only if both arguments are exactly equal.

equal returns true only if both arguments are exactly equal .