Project has been created.
This commit is contained in:
commit
20eed64a96
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Go template
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
vendor/
|
||||
glide.lock
|
||||
.DS_Store
|
||||
dist/
|
||||
debug
|
32
.vscode/launch.json
vendored
Normal file
32
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"remotePath": "",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
"program": "${workspaceRoot}/main.go",
|
||||
"env": {},
|
||||
"args": [],
|
||||
"showLog": true
|
||||
},
|
||||
{
|
||||
"name": "File Debug",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"remotePath": "",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
"program": "${fileDirname}",
|
||||
"env": {},
|
||||
"args": [],
|
||||
"showLog": true
|
||||
}
|
||||
|
||||
]
|
||||
}
|
11
.vscode/settings.json
vendored
Normal file
11
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
// Specifies Lint tool name.
|
||||
"go.lintTool": "gometalinter",
|
||||
|
||||
// Flags to pass to Lint tool (e.g. ["-min_confidence=.8"])
|
||||
"go.lintFlags": [
|
||||
"--config=${workspaceRoot}/golint.json"
|
||||
]
|
||||
|
||||
}
|
17
examples/hello/main.go
Normal file
17
examples/hello/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := overflow_gateway_websocket.NewServer()
|
||||
s.OnPreRequest(func() {
|
||||
|
||||
})
|
||||
s.OnPostRequest(func() {
|
||||
|
||||
})
|
||||
|
||||
s.ListenAndServe()
|
||||
}
|
9
glide.yaml
Normal file
9
glide.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
package: git.loafle.net/overflow/overflow_gateway_websocket
|
||||
import:
|
||||
- package: github.com/valyala/fasthttp
|
||||
version: v20160617
|
||||
- package: github.com/fasthttp-contrib/websocket
|
||||
- package: github.com/garyburd/redigo
|
||||
version: v1.1.0
|
||||
subpackages:
|
||||
- redis
|
19
protocol/server_error.go
Normal file
19
protocol/server_error.go
Normal file
@ -0,0 +1,19 @@
|
||||
package protocol
|
||||
|
||||
type ServerErrorCode int
|
||||
|
||||
const (
|
||||
ServerErrorCodeParse ServerErrorCode = -32700
|
||||
ServerErrorCodeInvalidRequest ServerErrorCode = -32600
|
||||
ServerErrorCodeNotFoundMethod ServerErrorCode = -32601
|
||||
ServerErrorCodeInvalidParams ServerErrorCode = -32602
|
||||
ServerErrorCodeInternal ServerErrorCode = -32603
|
||||
// -32000 ~ -32099
|
||||
ServerErrorCodeServer ServerErrorCode = -32000
|
||||
)
|
||||
|
||||
type ServerError struct {
|
||||
Code ServerErrorCode `json:"code"`
|
||||
Message interface{} `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
17
protocol/server_request.go
Normal file
17
protocol/server_request.go
Normal file
@ -0,0 +1,17 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type ServerRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params *json.RawMessage `json:"params"`
|
||||
Id *json.RawMessage `json:"id"`
|
||||
}
|
||||
|
||||
func (r *ServerRequest) reset() {
|
||||
r.Method = ""
|
||||
r.Params = nil
|
||||
r.Id = nil
|
||||
}
|
11
protocol/server_response.go
Normal file
11
protocol/server_response.go
Normal file
@ -0,0 +1,11 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type ServerResponse struct {
|
||||
Id *json.RawMessage `json:"id"`
|
||||
Result interface{} `json:"result"`
|
||||
Error interface{} `json:"error"`
|
||||
}
|
12
pubsub/pubsub.go
Normal file
12
pubsub/pubsub.go
Normal file
@ -0,0 +1,12 @@
|
||||
package pubsub
|
||||
|
||||
type (
|
||||
OnSubscribeFunc func(channel string, payload string)
|
||||
)
|
||||
|
||||
type Pubsub interface {
|
||||
Subscribe(cb OnSubscribeFunc)
|
||||
}
|
||||
|
||||
type pubSub struct {
|
||||
}
|
24
pubsub/redis/redis.go
Normal file
24
pubsub/redis/redis.go
Normal file
@ -0,0 +1,24 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.loafle.net/overflow/overflow_gateway_websocket/pubsub"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
)
|
||||
|
||||
type redisPubSub struct {
|
||||
pool *redis.Pool
|
||||
}
|
||||
|
||||
func New() pubsub.Pubsub {
|
||||
r := &redisPubSub{}
|
||||
r.pool = &redis.Pool{
|
||||
MaxIdle: 3,
|
||||
IdleTimeout: 240 * time.Second,
|
||||
Dial: func() (redis.Conn, error) {
|
||||
return redis.Dial("tcp", addr)
|
||||
},
|
||||
}
|
||||
return r
|
||||
}
|
54
server.go
Normal file
54
server.go
Normal file
@ -0,0 +1,54 @@
|
||||
package overflow_gateway_websocket
|
||||
|
||||
type (
|
||||
// OnPreRequestFunc is callback function
|
||||
OnPreRequestFunc func()
|
||||
OnPostRequestFunc func()
|
||||
OnPreNotifyFunc func()
|
||||
OnPrePushFunc func()
|
||||
)
|
||||
|
||||
type Server interface {
|
||||
OnPreRequest(cb OnPreRequestFunc)
|
||||
OnPostRequest(cb OnPostRequestFunc)
|
||||
OnPreNotify(cb OnPreNotifyFunc)
|
||||
OnPrePush(cb OnPrePushFunc)
|
||||
ListenAndServe()
|
||||
}
|
||||
|
||||
type server struct {
|
||||
onPreRequestListeners []OnPreRequestFunc
|
||||
onPostRequestListeners []OnPostRequestFunc
|
||||
onPreNotifyListeners []OnPreNotifyFunc
|
||||
onPrePushListeners []OnPrePushFunc
|
||||
}
|
||||
|
||||
func NewServer() Server {
|
||||
s := &server{
|
||||
onPreRequestListeners: make([]OnPreRequestFunc, 0),
|
||||
onPostRequestListeners: make([]OnPostRequestFunc, 0),
|
||||
onPreNotifyListeners: make([]OnPreNotifyFunc, 0),
|
||||
onPrePushListeners: make([]OnPrePushFunc, 0),
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *server) OnPreRequest(cb OnPreRequestFunc) {
|
||||
s.onPreRequestListeners = append(s.onPreRequestListeners, cb)
|
||||
}
|
||||
|
||||
func (s *server) OnPostRequest(cb OnPostRequestFunc) {
|
||||
s.onPostRequestListeners = append(s.onPostRequestListeners, cb)
|
||||
}
|
||||
|
||||
func (s *server) OnPreNotify(cb OnPreNotifyFunc) {
|
||||
s.onPreNotifyListeners = append(s.onPreNotifyListeners, cb)
|
||||
}
|
||||
|
||||
func (s *server) OnPrePush(cb OnPrePushFunc) {
|
||||
s.onPrePushListeners = append(s.onPrePushListeners, cb)
|
||||
}
|
||||
|
||||
func (s *server) ListenAndServe() {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user