Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) CheckSckey(sckey, title string) (bool, error)
- func (c *Client) CheckSckeyWithContext(ctx context.Context, sckey, title string) (bool, error)
- func (c *Client) Send(sckey, title, message string) error
- func (c *Client) SendWithContext(ctx context.Context, sckey, title, message string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyTitle = errors.New("serverchan: empty title") // Empty title. ErrBadPushToken = errors.New("serverchan: bad push token") // Bad push token. ErrDuplicateMessage = errors.New("serverchan: duplicate message") // Duplicate message. ErrNotSuccess = errors.New("serverchan: respond with not success") // Not success, used when respond non-json or non-zero errno. )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct{}
Client represents a serverchan client. Please visit http://sc.ftqq.com/3.version for details.
func NewClient ¶
func NewClient() *Client
NewClient creates a default Client.
Example ¶
client := serverchan.NewClient()
_ = client.Send(sckey, "test title", "test message")
_, _ = client.CheckSckey("xxx", "check sckey")
func (*Client) CheckSckey ¶
CheckSckey sends a test message to serverchan to check if the sckey is valid.
Example ¶
client := serverchan.NewClient()
ok, err := client.CheckSckey(sckey, "message for checking sckey")
if err != nil {
log.Println("Failed to send message:", err)
} else if !ok {
log.Println("Invalid sckey")
} else {
log.Println("Valid sckey")
}
func (*Client) CheckSckeyWithContext ¶ added in v1.0.1
CheckSckeyWithContext sends a test message to serverchan to check if the sckey is valid (with context).
Example ¶
client := serverchan.NewClient()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
ok, err := client.CheckSckeyWithContext(ctx, sckey, "message for checking sckey")
if errors.Is(err, context.DeadlineExceeded) {
log.Println("Failed to send message: timeout")
} else if err != nil {
log.Println("Failed to send message:", err)
} else if !ok {
log.Println("Invalid sckey")
} else {
log.Println("Valid sckey")
}
func (*Client) Send ¶
Send sends a message to serverchan using given sckey.
Example ¶
client := serverchan.NewClient()
err := client.Send(sckey, "test title", "# test message\n## sub title\n+ item1\n+ [item2](https://www.google.co.jp)")
if err != nil {
log.Println("Failed to send message:", err)
} else {
log.Println("Success to send message")
}
func (*Client) SendWithContext ¶ added in v1.0.1
SendWithContext sends a message to serverchan using given sckey (with context).
Example ¶
client := serverchan.NewClient()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
err := client.SendWithContext(ctx, sckey, "test title", "test message")
if errors.Is(err, context.DeadlineExceeded) {
log.Println("Failed to send message: timeout")
} else if err != nil {
log.Println("Failed to send message:", err)
} else {
log.Println("Success to send message")
}
Click to show internal directories.
Click to hide internal directories.