32 lines
707 B
Go
32 lines
707 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func PostToMicroblog(location string, text string) {
|
|
if len(MicroblogUrl) == 0 || len(MicroblogToken) == 0 {
|
|
// Microblog.pub deactivated
|
|
return
|
|
}
|
|
if len(text) == 0 {
|
|
text = location
|
|
}
|
|
note := &struct {
|
|
Content string `json:"content"`
|
|
}{
|
|
Content: "[" + text + "](" + location + ")",
|
|
}
|
|
bytesRepresentation, err := json.Marshal(note)
|
|
if err != nil {
|
|
return
|
|
}
|
|
client := &http.Client{}
|
|
req, _ := http.NewRequest("POST", MicroblogUrl+"api/new_note", bytes.NewBuffer(bytesRepresentation))
|
|
req.Header.Add("Content-Type", "application/json")
|
|
req.Header.Add("Authorization", "Bearer "+MicroblogToken)
|
|
_, _ = client.Do(req)
|
|
}
|