11// Package confpar provide the core parameters of the config
22package confpar
33
4- import "time"
4+ import (
5+ "encoding/json"
6+ "time"
7+ )
58
69// Access provides rules around any access
710type Access struct {
@@ -19,7 +22,7 @@ type Access struct {
1922type AccessesWebhook struct {
2023 URL string `json:"url"` // URL to call
2124 Headers map [string ]string `json:"headers"` // Token to use in the
22- Timeout time. Duration `json:"timeout"` // Max time request can take
25+ Timeout Duration `json:"timeout"` // Max time request can take
2326}
2427
2528// SyncAndDelete provides
@@ -65,7 +68,7 @@ type Content struct {
6568 PublicHost string `json:"public_host"` // Public host to listen on
6669 MaxClients int `json:"max_clients"` // Maximum clients who can connect
6770 HashPlaintextPasswords bool `json:"hash_plaintext_passwords"` // Overwrite plain-text passwords with hashed equivalents
68- IdleTimeout time. Duration `json:"idle_timeout"` // Maximum idle time for client connections
71+ IdleTimeout Duration `json:"idle_timeout"` // Maximum idle time for client connections
6972 Accesses []* Access `json:"accesses"` // Accesses offered to users
7073 PassiveTransferPortRange * PortRange `json:"passive_transfer_port_range"` // Listen port range
7174 Extensions Extensions `json:"extensions"` // Extended features
@@ -74,3 +77,21 @@ type Content struct {
7477 TLSRequired string `json:"tls_required"`
7578 AccessesWebhook * AccessesWebhook `json:"accesses_webhook"` // Webhook to call when accesses are updated
7679}
80+
81+ // Duration wraps time.Duration to allow unmarshaling from JSON strings
82+ // in Go duration format (e.g., "5m", "30s", "1h")
83+ type Duration struct {
84+ time.Duration
85+ }
86+
87+ func (d * Duration ) MarshalJSON () ([]byte , error ) {
88+ return json .Marshal (d .String ())
89+ }
90+
91+ func (d * Duration ) UnmarshalJSON (b []byte ) (err error ) {
92+ var s string
93+ if err = json .Unmarshal (b , & s ); err == nil {
94+ d .Duration , err = time .ParseDuration (s )
95+ }
96+ return
97+ }
0 commit comments