/godactor

Primary LanguageGoGNU General Public License v3.0GPL-3.0

game server framework

a actor model framework written in Go. it has implemented server discovery using ETCD.

Getting Started

1.Installing

To start using godactor, install Go and run go get:

$ go get -u github.com/wwj31/godactor

2.Quick Start

Copy and paste the following code in your main files

package main

import (
	"fmt"
	"time"

	"github.com/wwj31/godactor/actor"
)
type PingActor struct{ actor.ActorHanlerBase }
type PongActor struct{ actor.ActorHanlerBase }

func main() {
	system, _ := actor.System()
	ping := actor.New("ping", &PingActor{})
	pong := actor.New("pong", &PongActor{})
	system.Regist(ping)
	system.Regist(pong)
	select {}
}

// PingActor
func (s *PingActor) Init() {
	s.AddTimer(2*time.Second, -1, func(dt int64) {
		s.Send("pong", "this is data")
	})
}
func (s *PingActor) HandleMessage(sourceId, targetId string, msg interface{}) {
	switch msg {
	case 99999:
		fmt.Println(sourceId, targetId)
		fmt.Println()
	}
}

//PongActor
func (s *PongActor) HandleMessage(sourceId, targetId string, msg interface{}) {
	switch msg {
	case "this is data":
		fmt.Println(sourceId, targetId)
		s.Send(sourceId, 99999)
	}
}

add the following lines,in your go.mod

replace (
    github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
    google.golang.org/grpc => google.golang.org/grpc v1.26.0
)