swift

package module
v0.0.0-...-6e4db02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

README

swift

Swift is an easy to use, fast, distributed, supporting multi process multi process game server framework written by Golang.

warning

This framework is under development, so please don't try it at the moment.

how to use

import (
	"github.com/pengzj/swift"
	"./app/servers/connector/handler"
)

func main()  {
	app := swift.CreateApp()
	app.SetConfigPath("/Users/francis.peng/Work/PfsGame/config")
	app.SetLogPath("/Users/francis.peng/Project/logs/pfs")

	app.HandleFunc("user.login", handler.UserLogin)
	app.RegisterHandler("onChat")

	app.Run()
}

server config directory

include files:
|-- master.json
|-- servers.json
|-- secret.key

master.json

{
  "id": "master-server-1",
  "host": "127.0.0.1",
  "port": "3015"
}

servers.json

[
  {"type": "connector", "id": "connector-server-1","clientHost": "127.0.0.1", "clientPort": "3301", "host": "127.0.0.1", "port": "3401", "frontend": true, "connType": "tcp"},
  {"type": "connector", "id": "connector-server-2","clientHost": "127.0.0.1", "clientPort": "3302", "host": "127.0.0.1", "port": "3402", "frontend": true, "connType": "tcp"},
  {"type": "rank", "id": "rank-server-1","host": "127.0.0.1", "port": "3403", "frontend": false}
]

secret.key

asdfkksad$sadfk

to do list

data async to db in progress
optimize internal interface
manage tool
service
test case
benchmark

Documentation

Index

Constants

View Source
const (
	SERVER_MASTER = "master"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

func CreateApp

func CreateApp() *Application

func GetApp

func GetApp() *Application

func (*Application) Broadcast

func (app *Application) Broadcast(serverType, route string, data []byte)

func (*Application) GetConnectionOption

func (app *Application) GetConnectionOption(serverType string) *option.ConnectorOption

func (*Application) GetDB

func (app *Application) GetDB(name string) *sql.DB

func (*Application) GetRpcClient

func (app *Application) GetRpcClient(serverType string) *grpc.ClientConn

func (*Application) HandleFunc

func (app *Application) HandleFunc(name string, handler func(*hub.Session, []byte) []byte)

func (*Application) IsMaster

func (app *Application) IsMaster() bool

func (*Application) RegisterBeforeHandler

func (app *Application) RegisterBeforeHandler(handler func(*hub.Session, string) error)

func (*Application) RegisterDB

func (app *Application) RegisterDB(name, dbType, dsn string)

func (*Application) RegisterHandler

func (app *Application) RegisterHandler(name string)

func (*Application) RegisterRPC

func (app *Application) RegisterRPC(handler func())

func (*Application) Route

func (app *Application) Route(serverType string, handler func(session *hub.Session) string)

func (*Application) Run

func (app *Application) Run()

func (*Application) SetConfigPath

func (app *Application) SetConfigPath(path string)

func (*Application) SetConnectionOption

func (app *Application) SetConnectionOption(serverType string, option *option.ConnectorOption)

func (*Application) SetLogPath

func (app *Application) SetLogPath(path string)

type EnumState

type EnumState uint8
const (
	STATE_INITED  EnumState = iota //app has inited
	STATE_START                    // app start
	STATE_STARTED                  // app has started
	START_STOPED                   // app has stoped
)

Directories

Path Synopsis
tcp
udp
Package pb is a generated protocol buffer package.
Package pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL