Documentation ¶
Index ¶
Constants ¶
View Source
const ( FlagLimit = "limit" FlagFromDate = "from" FlagToDate = "to" FlagJson = "json" FromDateTime = "fromDateTime" ToDateTime = "toDateTime" )
View Source
const ( PersistentFlagConfig = "config" PersistentFlagSender = "sender" )
View Source
const ( FlagServerInterval = "interval" SmartlockCheckInterval = time.Hour * 2 )
View Source
const (
AppName = "nuki-logger"
)
Variables ¶
View Source
var ( BuildDate string ApplicationVersion string )
View Source
var ( QueryCmd = &cobra.Command{ Use: "query", Short: "Query logs from the Nuki API", PreRunE: func(cmd *cobra.Command, args []string) error { lim := viper.GetInt(FlagLimit) if lim <= 0 || lim > 50 { return fmt.Errorf("limit is out of bound. Should be between 1 and 50") } if viper.GetString(FlagFromDate) != "" { fromDate, err := time.Parse(time.RFC3339, viper.GetString(FlagFromDate)) if err != nil { return err } viper.Set(FromDateTime, fromDate) } if viper.GetString(FlagToDate) != "" { toDate, err := time.Parse(time.RFC3339, viper.GetString(FlagToDate)) if err != nil { return err } viper.Set(ToDateTime, toDate) } return nil }, RunE: QueryRun, } )
View Source
var ( RootCmd = &cobra.Command{ Use: "nuki-logger", Short: "Query Nuki api for most recent logs", SilenceUsage: true, SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if strings.Contains(cmd.CommandPath(), "version") { return nil } var requiredFlagsMissing []string for _, v := range requiredStringFlags { if viper.GetString(v) == "" { requiredFlagsMissing = append(requiredFlagsMissing, v) } } for _, v := range requiredStringSliceFlags { if len(viper.GetStringSlice(v)) == 0 { requiredFlagsMissing = append(requiredFlagsMissing, v) } } if len(requiredFlagsMissing) > 0 { return fmt.Errorf("the following flag(s) are required: %s", strings.Join(requiredFlagsMissing, ", ")) } if viper.GetString(PersistentFlagConfig) != "" { viper.SetConfigName(viper.GetString(PersistentFlagConfig)) } if err := config.LoadConfig(viper.GetViper()); err != nil { return err } return initSenders() }, RunE: run, } )
Functions ¶
func StringToTimeHourMinuteHookFunc ¶ added in v0.0.7
func StringToTimeHourMinuteHookFunc() mapstructure.DecodeHookFunc
Types ¶
type Config ¶
type Config struct { SmartlockID int64 `mapstructure:"smartlock_id"` NukiAPIToken string `mapstructure:"nuki_api_token"` AddressID int64 `mapstructure:"address_id"` Senders []SenderConfig `mapstructure:"senders"` TelegramBot struct { Enabled bool `mapstructure:"enabled"` SenderName string `mapstructure:"sender_name"` DefaultCheckIn TimeHourMinute `mapstructure:"default_check_in"` DefaultCheckOut TimeHourMinute `mapstructure:"default_check_out"` RestrictToChatIDs []int64 `mapstructure:"restrict_private_chat_ids"` } `mapstructure:"telegram_bot"` LogsReader nukiapi.LogsReader `mapstructure:"-"` SmartlockReader nukiapi.SmartlockReader `mapstructure:"-"` SmartlockAuthReader nukiapi.SmartlockAuthReader `mapstructure:"-"` ReservationsReader nukiapi.ReservationsReader `mapstructure:"-"` }
type QueryConfig ¶
type QueryConfig struct {
Config
}
type SenderConfig ¶
type SenderConfig struct { Name string `mapstructure:"name"` Telegram *messaging.TelegramSender `mapstructure:"telegram"` Console *messaging.ConsoleSender `mapstructure:"console"` }
type TimeHourMinute ¶ added in v0.0.7
TimeHourMinute is a time.Time representing only hours and minutes
Click to show internal directories.
Click to hide internal directories.