diff --git a/Notifier-Example.md b/Notifier-Example.md index b5754e2..aeb4142 100644 --- a/Notifier-Example.md +++ b/Notifier-Example.md @@ -1 +1,94 @@ -ok \ No newline at end of file +Below is a full example of a Statup notifier which will give you a good example of how to create your own. + +```go +package notifiers + +import ( + "github.com/hunterlong/statup/types" + "github.com/hunterlong/statup/core/notifier" +) + +type Example struct { + *notifier.Notification // create a new struct using *Notification +} + +const ( + EXAMPLE_METHOD = "example" // give your notifier a unique name (no spaces) +) + +var example = &Example{¬ifier.Notification{ + Method: EXAMPLE_METHOD, + Host: "http://exmaplehost.com", + Form: []notifier.NotificationForm{{ + Type: "text", + Title: "Host", + Placeholder: "Insert your Host here.", + DbField: "host", + }, { + Type: "text", + Title: "Username", + Placeholder: "Insert your Username here.", + DbField: "username", + }, { + Type: "password", + Title: "Password", + Placeholder: "Insert your Password here.", + DbField: "password", + }, { + Type: "number", + Title: "Port", + Placeholder: "Insert your Port here.", + DbField: "port", + }, { + Type: "text", + Title: "API Key", + Placeholder: "Insert your API Key here", + DbField: "api_key", + }, { + Type: "text", + Title: "API Secret", + Placeholder: "Insert your API Secret here", + DbField: "api_secret", + }, { + Type: "text", + Title: "Var 1", + Placeholder: "Insert your Var1 here", + DbField: "var1", + }, { + Type: "text", + Title: "Var2", + Placeholder: "Var2 goes here", + DbField: "var2", + }}}, +} + +// AddNotifier(example) inside init() is required! +func init() { + notifier.AddNotifier(example) +} + +// Run is required for the Notifier interface +func (n *Example) Run() error { + // this function can be a go routine if you need it + return nil +} + +// OnSave is required for the Notifier interface +func (n *Example) OnSave() error { + // this function is triggered when the notifier's form is saved + return nil +} + +// Select is required for the Notifier interface +func (n *Example) Select() *Notification { + return n.Notification +} + +func (n *Example) OnSuccess(s *types.Service) { + // When a service is successful this function will be triggered! +} + +func (n *Example) OnFailure(s *types.Service, f *types.Failure) { + // When a service is failing this function will be triggered! +} +``` \ No newline at end of file