gameframe

package module
v0.0.0-...-41dda67 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 14 Imported by: 0

README

gameframe

game micro service frame

feature

  1. custom codec
  2. custom marshaler
  3. reflect handler
  4. custom service discovery
  5. grpc
  6. group
  7. standalone mode
  8. timeout, retry, circuit break

in developing...

example:

package main

import (
	"errors"
	"flag"
	"github.com/zengjiwen/gameframe"
	"log"
	"os"
	"os/signal"
)

var _serverID = flag.String("serverid", "", "specify the server id")
var _serverType = flag.String("servertype", "", "specify the server type")
var _clientAddr = flag.String("clientaddr", "", "specify the client addr")
var _serviceAddr = flag.String("serviceaddr", "", "specify the service addr")

func main() {
	flag.Parse()

	if *_serverType == "gateway" {
		gameframe.RegisterClientHandler("hello", handleHello)
		if err := gameframe.Run(*_serverID, *_serverType,
			gameframe.WithClientAddr(*_clientAddr),
			gameframe.WithConcurrentMode("actor"),
			gameframe.WithServiceAddr(*_serviceAddr)); err != nil {
			log.Println(err)
			return
		}
	} else if *_serverType == "game" {
		room := Room{}
		gameframe.RegisterClientHandler("room.joinRoom", room.joinRoom)
		if err := gameframe.Run(*_serverID, *_serverType,
			gameframe.WithConcurrentMode("csp"),
			gameframe.WithServiceAddr(*_serviceAddr)); err != nil {
			log.Println(err)
			return
		}
	} else {
		log.Println(errors.New("incorrect server type"))
		return
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	select {
	case sig := <-c:
		log.Println("receive signal: %s", sig.String())
	case err := <-gameframe.GetDieChan():
		log.Println(err)
	}

	if err := gameframe.Shutdown(); err != nil {
		log.Println(err)
	}
}

func handleHello(session *gameframe.Session) {

}

type Room struct{}

func (r Room) joinRoom(session *gameframe.Session) {

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SessionExistErr = errors.New("session exist err")

Functions

func GetDieChan

func GetDieChan() chan error

func RegisterClientHandler

func RegisterClientHandler(route string, ch interface{})

func RegisterCodec

func RegisterCodec(cd codec.Codec)

func RegisterMarshaler

func RegisterMarshaler(ma marshaler.Marshaler)

func RegisterServerHandler

func RegisterServerHandler(route string, sh interface{})

func RegisterServiceDiscovery

func RegisterServiceDiscovery(sd servicediscovery.ServiceDiscovery)

func Run

func Run(serverID, serverType string, opts ...Option) error

func Shutdown

func Shutdown() error

Types

type Group

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

func NewGroup

func NewGroup(n string) *Group

func (*Group) Broadcast

func (g *Group) Broadcast(route string, arg interface{})

func (*Group) Join

func (g *Group) Join(s *sessions.Session) error

func (*Group) Leave

func (g *Group) Leave(s *sessions.Session)

func (*Group) Multicast

func (g *Group) Multicast(route string, arg interface{}, filter func(*sessions.Session) bool)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithClientAddr

func WithClientAddr(addr string) Option

func WithConcurrentMode

func WithConcurrentMode(mode string) Option

func WithSDAddr

func WithSDAddr(addr string) Option

func WithServiceAddr

func WithServiceAddr(addr string) Option

func WithStandalone

func WithStandalone() Option

type Session

type Session sessions.Session

Directories

Path Synopsis
rpc

Jump to

Keyboard shortcuts

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