func (hc *HipChat) Close() error {
	log.RemoveHandler(hc)
	return nil
}
Close cleans up any resources and de-registers the handler with the logger
package hipchat
import (
	"bytes"
	"encoding/json"
	"fmt"
	"html/template"
	"io/ioutil"
	stdhttp "net/http"
	"strings"
	"github.com/go-playground/log/v7"
	"github.com/go-playground/log/v7/handlers/http"
)
type APIVersion uint8
const (
	APIv2 APIVersion = iota
)
type Value struct {
	URL   string `json:"url,omitempty"`    
	Style string `json:"style,omitempty"`  
	Label string `json:"label"`            
	Icon  *Icon  `json:"icon,omitempty"`   
}
type Attribute struct {
	Value Value  `json:"value"`            
	Label string `json:"label,omitempty"`  
}
type Icon struct {
	URL       string `json:"url"`     
	URLRetina string `json:"url@2x"`  
}
type Activity struct {
	HTML string `json:"html"`            
	Icon *Icon  `json:"icon,omitempty"`  
}
type Thumbnail struct {
	URL       string `json:"url"`               
	URLRetina string `json:"url@2x"`            
	Width     uint   `json:"width,omitempty"`   
	Height    uint   `json:"height,omitempty"`  
}
type Description struct {
	Value  string `json:"value"`   
	Format string `json:"format"`  
}
type Card struct {
	Style            string       `json:"style"`                  
	Description      *Description `json:"description,omitempty"`  
	Format           string       `json:"format,omitempty"`       
	URL              string       `json:"url,omitempty"`          
	Title            string       `json:"title"`                  
	HipChatThumbnail *Thumbnail   `json:"thumbnail,omitempty"`    
	Attributes       []Attribute  `json:"attributes,omitempty"`   
	ID               string       `json:"id"`                     
	Icon             *Icon        `json:"icon,omitempty"`         
}
type Body struct {
	From          string `json:"from,omitempty"`            
	MessageFormat string `json:"message_format,omitempty"`  
	Color         string `json:"color,omitempty"`           
	AttachTo      string `json:"attach_to,omitempty"`       
	Notify        bool   `json:"notify,omitempty"`          
	Message       string `json:"message"`                   
	Card          *Card  `json:"card,omitempty"`
}
var defaultColors = [...]string{
	log.DebugLevel:  "green",
	log.InfoLevel:   "purple",
	log.NoticeLevel: "purple",
	log.WarnLevel:   "yellow",
	log.ErrorLevel:  "red",
	log.PanicLevel:  "red",
	log.AlertLevel:  "red",
	log.FatalLevel:  "red",
}
const (
	method          = "POST"
	defaultTemplate = `<p><b>{{ .Level.String }}</b></p>
        <p>{{ ts . }}</p>
        <p><b>{{ .Message }}</b></p>
        {{ range $f := .Fields }}
            <p><b>{{ $f.Key }}</b>: {{ $f.Value }}</p>
        {{ end }}`
)
type HipChat struct {
	*http.HTTP
	colors      [8]string
	template    *template.Template
	api         APIVersion
	application string
}
func New(api APIVersion, remoteHost string, contentType string, authToken string, application string) (*HipChat, error) {
	authToken = "Bearer " + authToken
	client := &stdhttp.Client{}
	req, err := stdhttp.NewRequest("GET", remoteHost+"?auth_test=true", nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("Authorization", authToken)
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != stdhttp.StatusAccepted {
		bt, _ := ioutil.ReadAll(resp.Body)
		return nil, fmt.Errorf("HipChat authorization failed\n %s", string(bt))
	}
	header := make(stdhttp.Header)
	header.Set("Content-Type", contentType)
	header.Set("Authorization", authToken)
	hc := &HipChat{
		colors:      defaultColors,
		api:         api,
		application: application,
	}
	hc.HTTP, _ = http.New(strings.TrimRight(remoteHost, "/")+"/notification", method, header)
	hc.HTTP.SetFormatFunc(formatFunc(hc))
	hc.SetTemplate(defaultTemplate)
	return hc, nil
}
func (hc *HipChat) SetTemplate(htmlTemplate string) {
	hc.template = template.Must(template.New("hipchat").Funcs(
		template.FuncMap{
			"ts": func(e log.Entry) (ts string) {
				ts = e.Timestamp.Format(hc.TimestampFormat())
				return
			},
		},
	).Parse(htmlTemplate))
}
func formatFunc(hc *HipChat) http.FormatFunc {
	return func(h *http.HTTP) http.Formatter {
		var bt []byte
		b := new(bytes.Buffer)
		body := new(Body)
		body.Notify = true
		return func(e log.Entry) []byte {
			bt = bt[0:0]
			b.Reset()
			body.From = hc.application
			body.Color = hc.colors[e.Level]
			_ = hc.template.ExecuteTemplate(b, "hipchat", e)
			body.Message = b.String()
			bt, _ = json.Marshal(body)
			return bt
		}
	}
}