Skip to content

Commit

Permalink
fix client
Browse files Browse the repository at this point in the history
  • Loading branch information
abobacode committed May 27, 2024
1 parent 5232d32 commit 84b58c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion alertbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func New(ctx context.Context, host, token string) error {
batchSize = 100
)

eventProcessor := NewTg(newClient(host, token))
eventProcessor := NewTg(NewClient(host, token))
cons := newConsumer(eventProcessor, eventProcessor, batchSize)

if err := cons.start(ctx); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions event-telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type Processor struct {
tg *client
tg *Client
offset int
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func FetchType(upd Update) Type {
return Message
}

func NewTg(client *client) *Processor {
func NewTg(client *Client) *Processor {
return &Processor{
tg: client,
}
Expand Down
16 changes: 8 additions & 8 deletions telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
"strconv"
)

type client struct {
type Client struct {
Host string
Path string
Client http.Client

token string
}

func (c *client) updates(offset, limit int) ([]Update, error) {
func (c *Client) updates(offset, limit int) ([]Update, error) {
query := url.Values{}

query.Add("offset", strconv.Itoa(offset))
Expand All @@ -37,7 +37,7 @@ func (c *client) updates(offset, limit int) ([]Update, error) {
return resp.Result, nil
}

func (c *client) sendMessage(chatID int, text string) error {
func (c *Client) sendMessage(chatID int, text string) error {
query := url.Values{}

query.Add("chat_id", strconv.Itoa(chatID))
Expand All @@ -52,7 +52,7 @@ func (c *client) sendMessage(chatID int, text string) error {
return nil
}

func (c *client) sendPhoto(chatID int, text, path string, buttons [][]string) error {
func (c *Client) sendPhoto(chatID int, text, path string, buttons [][]string) error {
keyboard := map[string]interface{}{
"keyboard": buttons,
"resize_keyboard": true,
Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *client) sendPhoto(chatID int, text, path string, buttons [][]string) er
return nil
}

func (c *client) sendFile(params map[string]string, paramName, fileName string, file *os.File) error {
func (c *Client) sendFile(params map[string]string, paramName, fileName string, file *os.File) error {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)

Expand Down Expand Up @@ -132,7 +132,7 @@ func (c *client) sendFile(params map[string]string, paramName, fileName string,
return nil
}

func (c *client) sendRequest(method string, query url.Values, value interface{}) error {
func (c *Client) sendRequest(method string, query url.Values, value interface{}) error {
u := url.URL{
Scheme: "https",
Host: c.Host,
Expand Down Expand Up @@ -164,8 +164,8 @@ func (c *client) sendRequest(method string, query url.Values, value interface{})
return nil
}

func newClient(host, token string) *client {
return &client{
func NewClient(host, token string) *Client {
return &Client{
Host: host,
Path: "bot" + token,
Client: http.Client{},
Expand Down

0 comments on commit 84b58c5

Please sign in to comment.