syntax cleanup
This commit is contained in:
parent
9f0ce0b66a
commit
05e1723fd2
1 changed files with 21 additions and 21 deletions
|
@ -32,7 +32,7 @@ var interrupt chan os.Signal
|
|||
type Config struct {
|
||||
PnutAccessToken string `ini:"pnut_access_token"`
|
||||
PnutUsername string `ini:"pnut_username"`
|
||||
MbUrl string `ini:"matterbridge_url"`
|
||||
MbURL string `ini:"matterbridge_url"`
|
||||
MbToken string `ini:"matterbridge_token"`
|
||||
Rooms []Room
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ type Room struct {
|
|||
|
||||
type Meta struct {
|
||||
Timestamp int `json:"timestamp"`
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
ChannelType string `json:"channel_type"`
|
||||
SubscriptionIds []string `json:"subscription_ids"`
|
||||
Stream Stream `json:"stream"`
|
||||
ConnectionId string `json:"connection_id"`
|
||||
ConnectionID string `json:"connection_id"`
|
||||
}
|
||||
|
||||
type Stream struct {
|
||||
|
@ -77,7 +77,7 @@ type MbMessage struct {
|
|||
ParentID string `json:"parent_id"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
ID string `json:"id"`
|
||||
Extra MbExtra `json"extra"`
|
||||
Extra MbExtra `json:"extra"`
|
||||
}
|
||||
|
||||
type MbExtra struct {
|
||||
|
@ -104,14 +104,14 @@ type PnutOembed struct {
|
|||
Version string `json:"version"`
|
||||
Type string `json:"type"`
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
URL string `json:"url"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
}
|
||||
|
||||
func subscribe(connection_id string, access_token string, rooms []Room) {
|
||||
func subscribe(connectionID string, accessToken string, rooms []Room) {
|
||||
params := url.Values{}
|
||||
params.Set("connection_id", connection_id)
|
||||
params.Set("connection_id", connectionID)
|
||||
for _, _room := range rooms {
|
||||
log.Printf(">> connecting channel %s ...", _room.ChannelID)
|
||||
url := "https://api.pnut.io/v1/channels/" + _room.ChannelID + "/messages?" + params.Encode()
|
||||
|
@ -120,7 +120,7 @@ func subscribe(connection_id string, access_token string, rooms []Room) {
|
|||
log.Println("!! unable to create request", err)
|
||||
}
|
||||
req.Header.Set("User-Agent", "pnut-bridge")
|
||||
req.Header.Add("Authorization", "Bearer "+access_token)
|
||||
req.Header.Add("Authorization", "Bearer "+accessToken)
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
@ -144,9 +144,9 @@ func receiveHandler(connection *websocket.Conn, conf *Config) {
|
|||
if err := json.Unmarshal(msg, &m); err != nil {
|
||||
log.Println("!! error unmarshaling msg", err)
|
||||
}
|
||||
if len(m.Meta.ConnectionId) > 0 {
|
||||
log.Println("<< connection", m.Meta.ConnectionId)
|
||||
subscribe(m.Meta.ConnectionId, conf.PnutAccessToken, conf.Rooms)
|
||||
if len(m.Meta.ConnectionID) > 0 {
|
||||
log.Println("<< connection", m.Meta.ConnectionID)
|
||||
subscribe(m.Meta.ConnectionID, conf.PnutAccessToken, conf.Rooms)
|
||||
continue
|
||||
}
|
||||
switch m.Meta.ChannelType {
|
||||
|
@ -182,7 +182,7 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) {
|
|||
log.Println("!! there is a problem creating json string", err)
|
||||
return
|
||||
}
|
||||
url := conf.MbUrl + "/api/message"
|
||||
url := conf.MbURL + "/api/message"
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
||||
if err != nil {
|
||||
log.Println("!! unable to create request", err)
|
||||
|
@ -199,9 +199,9 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) {
|
|||
log.Printf("<< %s", resp.Status)
|
||||
}
|
||||
|
||||
func getRoomGateway(rooms []Room, chan_id string) string {
|
||||
func getRoomGateway(rooms []Room, chanID string) string {
|
||||
for _, v := range rooms {
|
||||
if v.ChannelID == chan_id {
|
||||
if v.ChannelID == chanID {
|
||||
return v.Gateway
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ func getRoomGateway(rooms []Room, chan_id string) string {
|
|||
func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||
client := woodstock.NewClient("", "")
|
||||
client.SetAccessToken(conf.PnutAccessToken)
|
||||
channel_id := getPnutChannel(conf.Rooms, msg.Gateway)
|
||||
channelID := getPnutChannel(conf.Rooms, msg.Gateway)
|
||||
|
||||
text := msg.Text
|
||||
var raw []woodstock.Raw
|
||||
|
@ -231,7 +231,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
|||
Version: "1.0",
|
||||
Type: "photo",
|
||||
Title: file.Name,
|
||||
Url: file.URL,
|
||||
URL: file.URL,
|
||||
Width: im.Width,
|
||||
Height: im.Height,
|
||||
}
|
||||
|
@ -247,9 +247,9 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
|||
lines := strings.Split(wrapped, "\n")
|
||||
for _, line := range lines {
|
||||
line := msg.Username + " " + line
|
||||
log.Printf(">> sending message from %s to channel %s ...", msg.Gateway, channel_id)
|
||||
log.Printf(">> sending message from %s to channel %s ...", msg.Gateway, channelID)
|
||||
newmessage := woodstock.NewMessage{Text: line, Raw: raw}
|
||||
_, err := client.CreateMessage(channel_id, newmessage)
|
||||
_, err := client.CreateMessage(channelID, newmessage)
|
||||
if err != nil {
|
||||
log.Println("!! problem posting message to pnut.io", err)
|
||||
}
|
||||
|
@ -304,8 +304,8 @@ func main() {
|
|||
params := url.Values{}
|
||||
params.Set("access_token", conf.PnutAccessToken)
|
||||
|
||||
socketUrl := "wss://stream.pnut.io/v1/user?" + params.Encode()
|
||||
conn, _, err := websocket.DefaultDialer.Dial(socketUrl, nil)
|
||||
socketURL := "wss://stream.pnut.io/v1/user?" + params.Encode()
|
||||
conn, _, err := websocket.DefaultDialer.Dial(socketURL, nil)
|
||||
if err != nil {
|
||||
log.Fatal("!! error connectiong to pnut.io:", err)
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ func main() {
|
|||
log.Fatal("!! error during write to websocket:", err)
|
||||
}
|
||||
|
||||
url := conf.MbUrl + "/api/messages"
|
||||
url := conf.MbURL + "/api/messages"
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
log.Println("!! unable to create request", err)
|
||||
|
|
Loading…
Reference in a new issue