package slacker

import (
	"bytes"
	"encoding/json"
	"net/http"
)

type Slacker struct {
	URL      string
	Icon     string
	Username string
}

type payload struct {
	text     string `json:"text"`
	icon     string `json:"icon_url"`
	username string `json:"username"`
}

func (s *Slacker) Send(text string) error {

	payload, err := json.Marshal(payload{
		text:     text,
		icon:     s.Icon,
		username: s.Username,
	})
	if err != nil {
		return err
	}

	_, err = http.Post(s.URL, "application/json", bytes.NewBuffer(payload))
	return err
}

package slacker

import (
	"bytes"
	"encoding/json"
	"errors"
	"net/http"
)

type Slacker struct {
	URL      string
	Icon     string
	Username string
}

type payload struct {
	Text     string `json:"text"`
	Icon     string `json:"icon_url"`
	Username string `json:"username"`
}

func (s *Slacker) Send(text string) error {

	if len(s.URL) == 0 {
		return errors.New("URL is required")
	}

	payload, err := json.Marshal(payload{
		Text:     text,
		Icon:     s.Icon,
		Username: s.Username,
	})
	if err != nil {
		return err
	}

	_, err = http.Post(s.URL, "application/json", bytes.NewBuffer(payload))
	return err
}

Make payload contents public, so that they can be serialized
Make payload contents public, so that they can be serialized
