Coder Social home page Coder Social logo

gserver_gateway_demo's Introduction

Installation

go get github.com/gfandada/gserver

规范

由于gserver保证性能和健壮性,所以开发者可以把精力放到如何处理消息上,以下是gserver的handler规范
type MsgHandler func ([]interface{})[]interface{}
参数介绍:arg[0].(*network.RawMessage)
	    arg[1].(*service.Session)

type Test struct {
	a int
}

// 1.正常回复客户端
func GetHandler(arg []interface{}) []interface{} {
	// ..........
	return []interface{}{network.RawMessage{
		MsgId: uint16(2001),
		MsgData: &GetAck{
			Test: proto.String("hello service-game"),
		},
	}}
}

// 2.不需要回复客户端
func GetHandler(arg []interface{}) []interface{} {
	// ..........
	return nil
}

// 3.显式终止:自定义错误码(9527表示金币不足)
func GetHandler(arg []interface{}) []interface{} {
	// ..........
	if xxxx {
		panic(9527)
		// 客户端会自动收到错误:errid:9527 errstr:""
	}
	return nil
}

// 4.隐式终止:
func GetHandler(arg []interface{}) []interface{} {
	// ..........
	test := new(Test)
	test = nil
	test.a = 23
	// 运行时错误,空指针
	// 客户端会自动收到错误:
	// errid:1 errstr:"runtime error: invalid memory address or nil pointer dereference"
	return nil
}

// 5.同步更新session:
// 因为用户数据被设计成一个map[string]interface{}可以满足任何形式的用户数据写入
func GetHandler(arg []interface{}) []interface{} {
	// ....
	ret := network.RawMessage{
		MsgId: uint16(2001),
		MsgData: &GetAck{
			Test: proto.String("hello service-game"),
		},
	}
	// 获取or修改sess.....
	return []interface{}{ret}
}

gserver_gateway_demo's People

Contributors

gfandada avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.