godactor

module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: GPL-3.0

README

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)
	}
}


Jump to

Keyboard shortcuts

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