Go fmt
This commit is contained in:
parent
531b59bf95
commit
a4dd3b310d
9 changed files with 142 additions and 144 deletions
|
@ -240,4 +240,3 @@ func (a *Account) eventInternal(event *Event) error {
|
|||
return mxSendMessageAs(mx_room_id, typ, event.Text, mx_user_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ package appservice
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||
)
|
||||
|
||||
var db *gorm.DB
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package appservice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"net/http"
|
||||
"time"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -33,7 +33,7 @@ func init() {
|
|||
func mxGetApiCall(endpoint string, response interface{}) error {
|
||||
log.Debugf("Matrix GET request: %s\n", endpoint)
|
||||
|
||||
req, err := http.NewRequest("GET", config.Server + endpoint, nil)
|
||||
req, err := http.NewRequest("GET", config.Server+endpoint, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func mxPutApiCall(endpoint string, data interface{}, response interface{}) error
|
|||
|
||||
log.Debugf("Matrix PUT request: %s %s\n", endpoint, string(body))
|
||||
|
||||
req, err := http.NewRequest("PUT", config.Server + endpoint, bytes.NewBuffer(body))
|
||||
req, err := http.NewRequest("PUT", config.Server+endpoint, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func mxPostApiCall(endpoint string, data interface{}, response interface{}) erro
|
|||
|
||||
log.Debugf("Matrix POST request: %s %s\n", endpoint, string(body))
|
||||
|
||||
req, err := http.NewRequest("POST", config.Server + endpoint, bytes.NewBuffer(body))
|
||||
req, err := http.NewRequest("POST", config.Server+endpoint, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func mxPostApiCall(endpoint string, data interface{}, response interface{}) erro
|
|||
}
|
||||
|
||||
func mxDoAndParse(req *http.Request, response interface{}) error {
|
||||
req.Header.Add("Authorization", "Bearer " + registration.AsToken)
|
||||
req.Header.Add("Authorization", "Bearer "+registration.AsToken)
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
|
@ -125,7 +125,7 @@ func mxProfileDisplayname(userid string, displayname string) error {
|
|||
|
||||
func mxDirectoryRoom(alias string) (string, error) {
|
||||
var rep DirectoryRoomResponse
|
||||
err := mxGetApiCall("/_matrix/client/r0/directory/room/" + url.QueryEscape(alias), &rep)
|
||||
err := mxGetApiCall("/_matrix/client/r0/directory/room/"+url.QueryEscape(alias), &rep)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ func mxCreateRoom(name string, alias string, invite []string) (string, error) {
|
|||
Name: name,
|
||||
Topic: "",
|
||||
Invite: invite,
|
||||
CreationContent: map[string]interface{} {
|
||||
CreationContent: map[string]interface{}{
|
||||
"m.federate": false,
|
||||
},
|
||||
PowerLevels: map[string]interface{} {
|
||||
PowerLevels: map[string]interface{}{
|
||||
"invite": 100,
|
||||
"events": map[string]interface{} {
|
||||
"events": map[string]interface{}{
|
||||
"m.room.topic": 0,
|
||||
"m.room.avatar": 0,
|
||||
},
|
||||
|
@ -164,16 +164,16 @@ func mxCreateDirectRoomAs(name string, invite []string, as_user string) (string,
|
|||
Name: name,
|
||||
Topic: "",
|
||||
Invite: invite,
|
||||
CreationContent: map[string]interface{} {
|
||||
CreationContent: map[string]interface{}{
|
||||
"m.federate": false,
|
||||
},
|
||||
PowerLevels: map[string]interface{} {
|
||||
PowerLevels: map[string]interface{}{
|
||||
"invite": 100,
|
||||
},
|
||||
IsDirect: true,
|
||||
}
|
||||
var rep CreateRoomResponse
|
||||
err := mxPostApiCall("/_matrix/client/r0/createRoom?user_id=" + url.QueryEscape(as_user), &rq, &rep)
|
||||
err := mxPostApiCall("/_matrix/client/r0/createRoom?user_id="+url.QueryEscape(as_user), &rq, &rep)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func mxRoomInvite(room string, user string) error {
|
|||
UserId: user,
|
||||
}
|
||||
var rep struct{}
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/invite", &rq, &rep)
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/invite", &rq, &rep)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -195,21 +195,21 @@ func mxRoomKick(room string, user string, reason string) error {
|
|||
Reason: reason,
|
||||
}
|
||||
var rep struct{}
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/kick", &rq, &rep)
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/kick", &rq, &rep)
|
||||
return err
|
||||
}
|
||||
|
||||
func mxRoomJoinAs(room string, user string) error {
|
||||
rq := struct{}{}
|
||||
var rep RoomJoinResponse
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/join?user_id=" + url.QueryEscape(user), &rq, &rep)
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/join?user_id="+url.QueryEscape(user), &rq, &rep)
|
||||
return err
|
||||
}
|
||||
|
||||
func mxRoomLeaveAs(room string, user string) error {
|
||||
rq := struct{}{}
|
||||
var rep struct{}
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/leave?user_id=" + url.QueryEscape(user), &rq, &rep)
|
||||
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/leave?user_id="+url.QueryEscape(user), &rq, &rep)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,7 @@ func mxSendAs(room string, event_type string, content map[string]interface{}, us
|
|||
}
|
||||
|
||||
func mxSendMessageAs(room string, typ string, body string, user string) error {
|
||||
content := map[string]interface{} {
|
||||
content := map[string]interface{}{
|
||||
"msgtype": typ,
|
||||
"body": body,
|
||||
}
|
||||
|
@ -241,14 +241,14 @@ func mxPutStateAs(room string, event_type string, key string, content map[string
|
|||
}
|
||||
|
||||
func mxRoomNameAs(room string, name string, as_user string) error {
|
||||
content := map[string]interface{} {
|
||||
content := map[string]interface{}{
|
||||
"name": name,
|
||||
}
|
||||
return mxPutStateAs(room, "m.room.name", "", content, as_user)
|
||||
}
|
||||
|
||||
func mxRoomTopicAs(room string, topic string, as_user string) error {
|
||||
content := map[string]interface{} {
|
||||
content := map[string]interface{}{
|
||||
"topic": topic,
|
||||
}
|
||||
return mxPutStateAs(room, "m.room.topic", "", content, as_user)
|
||||
|
|
|
@ -3,14 +3,14 @@ package appservice
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@ -21,7 +21,6 @@ type Config struct {
|
|||
MatrixDomain string
|
||||
}
|
||||
|
||||
|
||||
var registration *mxlib.Registration
|
||||
var config *Config
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ type Handler interface {
|
|||
}
|
||||
|
||||
type EventType int
|
||||
|
||||
const (
|
||||
EVENT_JOIN EventType = iota
|
||||
EVENT_LEAVE
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package irc
|
||||
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
_ "os"
|
||||
"strings"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/lrstanley/girc"
|
||||
|
||||
|
@ -31,7 +31,7 @@ func (irc *IRC) SetHandler(h Handler) {
|
|||
irc.handler = h
|
||||
}
|
||||
|
||||
func(irc *IRC) Protocol() string {
|
||||
func (irc *IRC) Protocol() string {
|
||||
return "irc"
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ func (irc *IRC) Configure(c Configuration) error {
|
|||
go irc.connectLoop(client)
|
||||
|
||||
for i := 0; i < 42; i++ {
|
||||
time.Sleep(time.Duration(1)*time.Second)
|
||||
time.Sleep(time.Duration(1) * time.Second)
|
||||
if irc.conn != client {
|
||||
break
|
||||
}
|
||||
|
|
12
main.go
12
main.go
|
@ -1,25 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
_"strings"
|
||||
_ "strings"
|
||||
_ "time"
|
||||
_ "fmt"
|
||||
"encoding/json"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/appservice"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp"
|
||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||
)
|
||||
|
||||
type ConfigAccount struct {
|
||||
|
@ -29,7 +29,7 @@ type ConfigAccount struct {
|
|||
}
|
||||
|
||||
type ConfigFile struct {
|
||||
HttpBindAddr string`json:"http_bind_addr"`
|
||||
HttpBindAddr string `json:"http_bind_addr"`
|
||||
Registration string `json:"registration"`
|
||||
Server string `json:"homeserver_url"`
|
||||
DbType string `json:"db_type"`
|
||||
|
|
|
@ -84,4 +84,3 @@ type RoomJoinResponse struct {
|
|||
type RoomSendResponse struct {
|
||||
EventId string `json:"event_id"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue