Skip to content

Commit

Permalink
gofmt imports and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dzyanis committed Mar 16, 2022
1 parent e297bf1 commit 40b513e
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 82 deletions.
2 changes: 1 addition & 1 deletion cmd/sachet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}

// receiverConfByReceiver loops the receiver conf list and returns the first instance with that name
// receiverConfByReceiver loops the receiver conf list and returns the first instance with that name.
func receiverConfByReceiver(name string) *ReceiverConf {
for i := range config.Receivers {
rc := &config.Receivers[i]
Expand Down
3 changes: 2 additions & 1 deletion provider/aliyun/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"strings"

sachet "github.com/messagebird/sachet"

"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
"github.com/messagebird/sachet"
)

type Config struct {
Expand Down
8 changes: 4 additions & 4 deletions provider/aspsms/aspsms.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
"github.com/messagebird/sachet"
)

// Config is the configuration struct for AspSms provider
// Config is the configuration struct for AspSms provider.
type Config struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}

// AspSms contains the necessary values for the AspSms provider
// AspSms contains the necessary values for the AspSms provider.
type AspSms struct {
Config

httpClient *http.Client
}

// NewAspSms creates and returns a new AspSms struct
// NewAspSms creates and returns a new AspSms struct.
func NewAspSms(config Config) *AspSms {
return &AspSms{
config,
Expand All @@ -42,7 +42,7 @@ type requestPayload struct {

const apiUrl = "https://json.aspsms.com/SendSimpleTextSMS"

// Send sends SMS to user registered in configuration
// Send sends SMS to user registered in configuration.
func (c *AspSms) Send(message sachet.Message) error {
params := requestPayload{
Username: c.Username,
Expand Down
8 changes: 4 additions & 4 deletions provider/cm/cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
"github.com/messagebird/sachet"
)

// Config is the configuration struct for CM provider
// Config is the configuration struct for CM provider.
type Config struct {
ProductToken string `yaml:"producttoken"`
}

// CM contains the necessary values for the CM provider
// CM contains the necessary values for the CM provider.
type CM struct {
Config
}

var cmHTTPClient = &http.Client{Timeout: time.Second * 20}

// NewCM creates and returns a new CM struct
// NewCM creates and returns a new CM struct.
func NewCM(config Config) *CM {
return &CM{config}
}
Expand All @@ -48,7 +48,7 @@ type CMPayload struct {
} `json:"messages"`
}

// Send sends SMS to n number of people using Bulk SMS API
// Send sends SMS to n number of people using Bulk SMS API.
func (c *CM) Send(message sachet.Message) error {
smsURL := "https://gw.cmtelecom.com/v1.0/message"

Expand Down
14 changes: 7 additions & 7 deletions provider/exotel/exotel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ import (
"github.com/messagebird/sachet"
)

//Config configuration struct for exotel Client
// Config configuration struct for exotel Client.
type Config struct {
AccountSID string `yaml:"account_sid"`
AuthToken string `yaml:"auth_token"`
}

//ExotelRequestTimeout is the timeout for http request to exotel
// ExotelRequestTimeout is the timeout for http request to exotel.
const ExotelRequestTimeout = time.Second * 20

//Exotel is the exte Exotel
// Exotel is the exte Exotel.
type Exotel struct {
AccountSid string
Token string
}

//NewExotel creates a new
// NewExotel creates a new.
func NewExotel(config Config) *Exotel {
Exotel := &Exotel{AccountSid: config.AccountSID, Token: config.AuthToken}
return Exotel
}

//Send send sms to n number of people using bulk sms api
// Send send sms to n number of people using bulk sms api.
func (c *Exotel) Send(message sachet.Message) (err error) {
smsURL := fmt.Sprintf("https://twilix.exotel.in/v1/Accounts/%s/Sms/send.json", c.AccountSid)
var request *http.Request
var resp *http.Response

form := url.Values{"From": {message.From}, "Body": {message.Text}, "To": message.To}

// preparing the request
// preparing the request.
request, err = http.NewRequest("POST", smsURL, strings.NewReader(form.Encode()))
if err != nil {
return
Expand All @@ -49,7 +49,7 @@ func (c *Exotel) Send(message sachet.Message) (err error) {
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.Header.Set("User-Agent", "SachetV1.0")

// calling the endpoint
// calling the endpoint.
httpClient := &http.Client{}
httpClient.Timeout = ExotelRequestTimeout

Expand Down
8 changes: 4 additions & 4 deletions provider/freemobile/freemobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
"github.com/messagebird/sachet"
)

// Config is the configuration struct for FreeMobile provider
// Config is the configuration struct for FreeMobile provider.
type Config struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
URL string `yaml:"url"`
}

// FreeMobile contains the necessary values for the FreeMobile provider
// FreeMobile contains the necessary values for the FreeMobile provider.
type FreeMobile struct {
Config
}

var freemobileHTTPClient = &http.Client{Timeout: time.Second * 20}

// NewFreeMobile creates and returns a new FreeMobile struct
// NewFreeMobile creates and returns a new FreeMobile struct.
func NewFreeMobile(config Config) *FreeMobile {
if config.URL == "" {
config.URL = "https://smsapi.free-mobile.fr/sendmsg"
Expand All @@ -38,7 +38,7 @@ type payload struct {
Message string `json:"msg"`
}

// Send sends SMS to user registered in configuration
// Send sends SMS to user registered in configuration.
func (c *FreeMobile) Send(message sachet.Message) error {
params := payload{
User: c.Username,
Expand Down
10 changes: 5 additions & 5 deletions provider/ghasedak/ghasedak.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import (
"github.com/messagebird/sachet"
)

// Retrieving required data from 'ghasedak' sections of config.yaml
// Retrieving required data from 'ghasedak' sections of config.yaml.
type Config struct {
APIToken string `yaml:"api_token"`
}

// Creating the KaveNegar to contain provider data
// Creating the KaveNegar to contain provider data.
type Ghasedak struct {
Config
HTTPClient *http.Client // The HTTP client to send requests on
HTTPClient *http.Client // The HTTP client to send requests on.
}

// Ghasedak creates and returns a new Ghasedak struct
// Ghasedak creates and returns a new Ghasedak struct.
func NewGhasedak(config Config) *Ghasedak {
return &Ghasedak{
config,
&http.Client{Timeout: time.Second * 20},
}
}

// Building the API and call the Ghasedak endpoint to send SMS to the configured receptor from config.yaml
// Building the API and call the Ghasedak endpoint to send SMS to the configured receptor from config.yaml.
func (ns *Ghasedak) Send(message sachet.Message) error {
endpoint := "https://api.ghasedak.me/v2/sms/send/pair"
data := url.Values{}
Expand Down
14 changes: 7 additions & 7 deletions provider/infobip/infobip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"github.com/messagebird/sachet"
)

//Config configuration struct for Infobip Client
// Config configuration struct for Infobip Client.
type Config struct {
Token string `yaml:"token"`
Secret string `yaml:"secret"`
}

//InfobipRequestTimeout is the timeout for http request to Infobip
// InfobipRequestTimeout is the timeout for http request to Infobip.
const InfobipRequestTimeout = time.Second * 20

//Infobip is the exte Infobip
// Infobip is the exte Infobip.
type Infobip struct {
Config
}
Expand All @@ -38,13 +38,13 @@ type InfobipPayload struct {
Messages []InfobipMessage `json:"messages"`
}

//NewInfobip creates a new
// NewInfobip creates a new.
func NewInfobip(config Config) *Infobip {
Infobip := &Infobip{config}
return Infobip
}

//Send send sms to n number of people using bulk sms api
// Send send sms to n number of people using bulk sms api.
func (c *Infobip) Send(message sachet.Message) (err error) {
smsURL := "https://api.infobip.com/sms/2/text/advanced"
// smsURL = "http://requestb.in/pwf2ufpw"
Expand All @@ -70,7 +70,7 @@ func (c *Infobip) Send(message sachet.Message) (err error) {
return err
}

// preparing the request
// preparing the request.
request, err = http.NewRequest("POST", smsURL, bytes.NewBuffer(data))
if err != nil {
return
Expand All @@ -79,7 +79,7 @@ func (c *Infobip) Send(message sachet.Message) (err error) {
request.SetBasicAuth(c.Token, c.Secret)
request.Header.Set("Content-Type", "application/json")
request.Header.Set("User-Agent", "SachetV1.0")
// calling the endpoint
// calling the endpoint.
httpClient := &http.Client{}
httpClient.Timeout = InfobipRequestTimeout

Expand Down
18 changes: 12 additions & 6 deletions provider/kannel/kannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,37 @@ import (
"github.com/messagebird/sachet"
)

//Config configuration struct for Kannel Client
// Config configuration struct for Kannel Client.
type Config struct {
URL string `yaml:"url"`
User string `yaml:"username"`
Pass string `yaml:"password"`
}

//KannelRequestTimeout is the timeout for http request to Kannel
// KannelRequestTimeout is the timeout for http request to Kannel.
const KannelRequestTimeout = time.Second * 20

//Kannel is the exte Kannel
// Kannel is the exte Kannel.
type Kannel struct {
Config
}

//NewKannel creates a new
// NewKannel creates a new.
func NewKannel(config Config) *Kannel {
Kannel := &Kannel{config}
return Kannel
}

//Send send sms to n number of people using bulk sms api
// Send send sms to n number of people using bulk sms api.
func (c *Kannel) Send(message sachet.Message) (err error) {
for _, recipient := range message.To {
queryParams := url.Values{"from": {message.From}, "to": {recipient}, "text": {message.Text}, "user": {c.User}, "pass": {c.Pass}}
queryParams := url.Values{
"from": {message.From},
"to": {recipient},
"text": {message.Text},
"user": {c.User},
"pass": {c.Pass},
}

request, err := http.NewRequest("GET", c.URL, nil)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions provider/kavenegar/kavenegar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ import (
"github.com/messagebird/sachet"
)

// Retrieving required data from 'kavenegar' sections of config.yaml
// Retrieving required data from 'kavenegar' sections of config.yaml.
type Config struct {
APIToken string `yaml:"api_token"`
PhoneNumbers []string `yaml:"phone_numbers"`
}

// Creating the KaveNegar to contain provider data
// Creating the KaveNegar to contain provider data.
type KaveNegar struct {
Config
HTTPClient *http.Client // The HTTP client to send requests on
HTTPClient *http.Client // The HTTP client to send requests on.
}

// KaveNegar creates and returns a new KaveNegar struct
// KaveNegar creates and returns a new KaveNegar struct.
func NewKaveNegar(config Config) *KaveNegar {
return &KaveNegar{
config,
&http.Client{Timeout: time.Second * 20},
}
}

// Building the API and call the KaveNegar endpoint to send SMS to the configured receptor from config.yaml
// Building the API and call the KaveNegar endpoint to send SMS to the configured receptor from config.yaml.
func (ns *KaveNegar) Send(message sachet.Message) error {
url := "https://api.kavenegar.com/v1/" + ns.APIToken + "/sms/send.json"
request, err := http.NewRequest("GET", url, nil)
Expand Down
1 change: 1 addition & 0 deletions provider/mailruim/mailruim.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mailruim

import (
botgolang "github.com/mail-ru-im/bot-golang"

"github.com/messagebird/sachet"
)

Expand Down
14 changes: 7 additions & 7 deletions provider/mediaburst/mediaburst.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@ import (
"github.com/messagebird/sachet"
)

//Config configuration struct for mediaburst Client
// Config configuration struct for mediaburst Client.
type Config struct {
APIKey string `yaml:"api_key"`
}

//MediaBurstRequestTimeout is the timeout for http request to mediaburst
// MediaBurstRequestTimeout is the timeout for http request to mediaburst.
const MediaBurstRequestTimeout = time.Second * 20

//MediaBurst is the exte MediaBurst
// MediaBurst is the exte MediaBurst.
type MediaBurst struct {
Config
}

//NewMediaBurst creates a new
// NewMediaBurst creates a new.
func NewMediaBurst(config Config) *MediaBurst {
MediaBurst := &MediaBurst{config}
return MediaBurst
}

//Send send sms to n number of people using bulk sms api
// Send send sms to n number of people using bulk sms api.
func (c *MediaBurst) Send(message sachet.Message) (err error) {
smsURL := "https://api.clockworksms.com/http/send.aspx"
var request *http.Request
var resp *http.Response

form := url.Values{"Key": {c.APIKey}, "From": {message.From}, "Content": {message.Text}, "To": message.To}

// preparing the request
// preparing the request.
request, err = http.NewRequest("GET", smsURL, strings.NewReader(form.Encode()))
if err != nil {
return
}

request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.Header.Set("User-Agent", "SachetV1.0")
// calling the endpoint
// calling the endpoint.
httpClient := &http.Client{}
httpClient.Timeout = MediaBurstRequestTimeout

Expand Down
Loading

0 comments on commit 40b513e

Please sign in to comment.