mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-22 02:12:20 +00:00
Merge pull request #1 from nxshock/refactor/go-default-project-structure
Changed project structure to default (Standard Golang project layout)
This commit is contained in:
commit
97969bbee1
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@
|
|||||||
|
|
||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
*.out
|
*.out
|
||||||
|
/cmd/cmd
|
||||||
|
10
.travis.yml
10
.travis.yml
@ -1,8 +1,10 @@
|
|||||||
language: go
|
language: go
|
||||||
sudo: false
|
sudo: false
|
||||||
go:
|
go:
|
||||||
- tip
|
- 1.12.x
|
||||||
|
env:
|
||||||
|
- GO111MODULE=on
|
||||||
before_install:
|
before_install:
|
||||||
- go get github.com/mattn/goveralls
|
- make update-deps
|
||||||
script:
|
install:
|
||||||
- $GOPATH/bin/goveralls -service=travis-ci
|
- make
|
@ -2,16 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
internal "github.com/nxshock/signaller/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
server *Server
|
server *internal.Server
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
server = New()
|
server = internal.New()
|
||||||
server.Address = "localhost"
|
server.Address = "localhost"
|
||||||
server.Backend = NewMemoryBackend()
|
server.Backend = internal.NewMemoryBackend()
|
||||||
server.Backend.Register("andrew", "1", "")
|
server.Backend.Register("andrew", "1", "")
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
import "github.com/nxshock/signaller/models"
|
import "github.com/nxshock/signaller/internal/models"
|
||||||
|
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
Register(username, password, device string) (token string, error *models.ApiError)
|
Register(username, password, device string) (token string, error *models.ApiError)
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "r0.5.0"
|
Version = "r0.5.0"
|
@ -1,9 +1,9 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/nxshock/signaller/models"
|
"github.com/nxshock/signaller/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func errorResponse(w http.ResponseWriter, code models.ApiError, httpCode int, message string) {
|
func errorResponse(w http.ResponseWriter, code models.ApiError, httpCode int, message string) {
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/nxshock/signaller/models"
|
"github.com/nxshock/signaller/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RootHandler(w http.ResponseWriter, r *http.Request) {
|
func RootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -58,7 +58,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
request.Identifier.User = strings.TrimPrefix(request.Identifier.User, "@")
|
request.Identifier.User = strings.TrimPrefix(request.Identifier.User, "@")
|
||||||
}
|
}
|
||||||
|
|
||||||
token, apiErr := server.Backend.Login(request.Identifier.User, request.Password, request.DeviceID)
|
token, apiErr := currServer.Backend.Login(request.Identifier.User, request.Password, request.DeviceID)
|
||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
errorResponse(w, *apiErr, http.StatusForbidden, "")
|
errorResponse(w, *apiErr, http.StatusForbidden, "")
|
||||||
return
|
return
|
||||||
@ -87,7 +87,7 @@ func LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiErr := server.Backend.Logout(token)
|
apiErr := currServer.Backend.Logout(token)
|
||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
errorResponse(w, *apiErr, http.StatusBadRequest, "") // TODO: check code
|
errorResponse(w, *apiErr, http.StatusBadRequest, "") // TODO: check code
|
||||||
return
|
return
|
||||||
@ -112,7 +112,7 @@ func RegisterHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
var request models.RegisterRequest
|
var request models.RegisterRequest
|
||||||
getRequest(r, &request) // TODO: handle error
|
getRequest(r, &request) // TODO: handle error
|
||||||
|
|
||||||
token, apiErr := server.Backend.Register(request.Username, request.Password, request.DeviceID)
|
token, apiErr := currServer.Backend.Register(request.Username, request.Password, request.DeviceID)
|
||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
errorResponse(w, *apiErr, http.StatusBadRequest, "")
|
errorResponse(w, *apiErr, http.StatusBadRequest, "")
|
||||||
return
|
return
|
||||||
@ -145,7 +145,7 @@ func SyncHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _ := server.Backend.Sync(token, request) // TODO: handle error
|
response, _ := currServer.Backend.Sync(token, request) // TODO: handle error
|
||||||
|
|
||||||
response.NextBatch = "123"
|
response.NextBatch = "123"
|
||||||
response.Rooms = models.RoomsSyncReply{}
|
response.Rooms = models.RoomsSyncReply{}
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var currServer Server
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
router *mux.Router
|
router *mux.Router
|
||||||
@ -24,13 +26,14 @@ func New() *Server {
|
|||||||
router.HandleFunc("/", RootHandler)
|
router.HandleFunc("/", RootHandler)
|
||||||
|
|
||||||
httpServer := new(http.Server)
|
httpServer := new(http.Server)
|
||||||
httpServer.Addr = ":80"
|
httpServer.Addr = ":8008"
|
||||||
httpServer.Handler = router
|
httpServer.Handler = router
|
||||||
|
|
||||||
server := &Server{
|
server := &Server{
|
||||||
httpServer: httpServer,
|
httpServer: httpServer,
|
||||||
router: router}
|
router: router}
|
||||||
|
|
||||||
|
currServer = *server
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nxshock/signaller/models"
|
"github.com/nxshock/signaller/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var first bool
|
var first bool
|
Loading…
Reference in New Issue
Block a user