Skip to content

Commit 55d719d

Browse files
committed
Upload 2019.01 meetup slides and resources
1 parent e5549f5 commit 55d719d

19 files changed

+623
-4
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@ Golang Korea에서 주최하는 밋업, 세미나 및 컨퍼런스의 발표 자
44

55

66

7-
## Golang Korea MeetUp in Seoul 12월
7+
## Golang Korea MeetUp in Seoul 2019.01
8+
9+
> [밋업 링크](https://www.meetup.com/Seoul-Go-Meetup/events/258121678/)
10+
11+
| 발표자 | 주제 | 발표 자료 | 코드 자료 |
12+
| -------- | --------------------------- | ------------------------------------------------------------ | -- |
13+
| 주원영님 | How we use Golang heybeauty | [How we use Golang heybeauty](slides/201901/how-we-golang-heybeauty.pdf) | - |
14+
| 최흥배님 | Golang 로그 라이브러리 zap | [고성능 로그 라이브러리 zap 소개](slides/201901/golang-log-library-zap.pdf) | - |
15+
| 한병일님 | 모듈화와 액터 | [모듈화와 액터](slides/201901/modularization-and-actor.pdf) |[예제](resources/201901/modularization-and-actor) |
16+
17+
## Golang Korea MeetUp in Seoul 2018.12
818

919
> [밋업 링크](https://www.meetup.com/ko-KR/Seoul-Go-Meetup/events/257399368/)
1020
1121
| 발표자 | 주제 | 발표 자료 |
1222
| -------- | ------------------------ | ------------------------------------------------------------ |
1323
| 이재용님 | Telegraf 코드 기여해보기 | [Telegraf 코드 기여해보기](slides/201812/contribute-open-source-with-telegraf.pdf) |
1424

15-
## Golang Korea MeetUp in Seoul 11월
25+
## Golang Korea MeetUp in Seoul 2018.11
1626

1727
> [밋업 링크](https://www.meetup.com/ko-KR/Seoul-Go-Meetup/events/256560625/)
1828
@@ -22,7 +32,7 @@ Golang Korea에서 주최하는 밋업, 세미나 및 컨퍼런스의 발표 자
2232
| 이용희님 | Golang으로 제작한 Network Scanner | [Golang으로 제작한 Network Scanner](slides/201811/make-network-scanner-with-go.pdf) |
2333
| 온수영님 | Golang으로 로그 적재 시스템 개발하기 | [Golang으로 로그 적재 시스템 개발하기](slides/201811/build-logging-system-with-go.pdf) |
2434

25-
## Golang Korea MeetUp in Seoul 8월
35+
## Golang Korea MeetUp in Seoul 2018.08
2636

2737
> [밋업 링크](https://www.meetup.com/Seoul-Go-Meetup/events/253672991/)
2838
@@ -32,7 +42,7 @@ Golang Korea에서 주최하는 밋업, 세미나 및 컨퍼런스의 발표 자
3242
| 이흥섭님 | 한글라이즈 재제작기 | [Remake of Hangulize](slides/201808/remake-of-hangulize.pdf) |
3343
| 김효준님 | ab180에서의 Go 도입기 | [Golang on Airbridge Airbloc](slides/201808/golang-on-airbridge-airbloc.pdf) |
3444

35-
## Golang Korea MeetUp in Seoul 7월
45+
## Golang Korea MeetUp in Seoul 2018.07
3646

3747
> [밋업 링크](https://www.meetup.com/Seoul-Go-Meetup/events/252632375)
3848
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package actor
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
"container/list"
7+
)
8+
9+
type AID struct {
10+
ActorID uint64
11+
NodeName string
12+
}
13+
14+
func (a *AID) String() string {
15+
return fmt.Sprintf("<%d, %s>", a.ActorID, a.NodeName)
16+
}
17+
18+
19+
type IActorReceiver interface {
20+
21+
GetNodeName() string
22+
}
23+
24+
type iActor interface {
25+
IActorReceiver
26+
getReceiver() reflect.Value
27+
getAID() *AID
28+
29+
setAID(aid *AID)
30+
call(function interface{}, args ...interface{}) ([]interface{}, error)
31+
}
32+
33+
var _ IActorReceiver = &Actor{}
34+
var _ iActor = &Actor{}
35+
36+
type Actor struct {
37+
aid *AID
38+
receiver reflect.Value
39+
queue *list.List
40+
inChan chan *ActorCall
41+
}
42+
43+
func (a *Actor) start(receiver IActorReceiver, aid *AID) bool {
44+
a.aid = aid
45+
a.receiver = reflect.ValueOf(receiver)
46+
a.queue = list.New()
47+
a.inChan = make(chan *ActorCall, 1)
48+
go a.loop()
49+
return true
50+
}
51+
52+
func (a *Actor) loop() {
53+
for {
54+
if a.queue.Len() == 0 {
55+
select {
56+
case actorCall := <-a.inChan:
57+
a.queue.PushBack(actorCall)
58+
}
59+
} else {
60+
select {
61+
case actorCall := <-a.inChan:
62+
a.queue.PushBack(actorCall)
63+
default:
64+
actorCall := a.queue.Front().Value.(*ActorCall)
65+
a.queue.Remove(a.queue.Front())
66+
a.process(actorCall)
67+
}
68+
}
69+
70+
}
71+
}
72+
73+
74+
func (a *Actor) GetNodeName() string {
75+
return a.aid.NodeName
76+
}
77+
78+
func (a *Actor) getAID() *AID {
79+
return a.aid
80+
}
81+
82+
func (a *Actor) getReceiver() reflect.Value {
83+
return a.receiver
84+
}
85+
86+
func (a *Actor) setAID(aid *AID) {
87+
a.aid = aid
88+
}
89+
90+
func (a *Actor) process(actorCall *ActorCall) {
91+
actorCall.Results = actorCall.Function.Call(actorCall.Args)
92+
if actorCall.Done != nil {
93+
actorCall.Done <- actorCall
94+
}
95+
}
96+
97+
98+
func (a *Actor) makeActorCall(done chan *ActorCall , function interface{}, args ...interface{}) *ActorCall {
99+
100+
v := reflect.ValueOf(function)
101+
if v.Kind() != reflect.Func {
102+
fn, _ := defaultActorSystem.findFunc(a, v.String())
103+
v = reflect.ValueOf(fn)
104+
105+
}
106+
107+
valuedArgs := make([]reflect.Value, len(args)+1)
108+
valuedArgs[0] = a.receiver
109+
for i, x := range args {
110+
valuedArgs[i+1] = reflect.ValueOf(x)
111+
}
112+
113+
return &ActorCall{Function:v, Args:valuedArgs, Done:done}
114+
115+
}
116+
117+
func (a *Actor) call(function interface{}, args ...interface{}) ([]interface{}, error) {
118+
done := make(chan *ActorCall, 0)
119+
a.inChan <- a.makeActorCall(done, function, args...)
120+
actorCall, _ := <-done
121+
return actorCall.GetResults()
122+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package actor
2+
3+
import (
4+
"context"
5+
"sync"
6+
"sync/atomic"
7+
"fmt"
8+
"runtime"
9+
"reflect"
10+
"strings"
11+
"net/http"
12+
)
13+
14+
type ActorProtocolType uint16
15+
16+
const (
17+
None ActorProtocolType = iota
18+
Web
19+
)
20+
21+
type Request struct {
22+
ActorID uint64
23+
NodeName string
24+
FuncName string
25+
Args []interface{}
26+
}
27+
28+
type Response struct {
29+
Err error
30+
Results []interface{}
31+
}
32+
33+
var defaultActorSystem *ActorSystem
34+
35+
func init() {
36+
defaultActorSystem = newActorSystem()
37+
}
38+
39+
type ActorSystem struct {
40+
mutex sync.RWMutex
41+
nowActorID uint64
42+
actorMapByAID map[*AID]iActor
43+
actorMapByNodeName map[string]iActor
44+
45+
server *http.Server
46+
serverCloseFunc context.CancelFunc
47+
}
48+
49+
func newActorSystem() *ActorSystem {
50+
d := &ActorSystem{
51+
actorMapByAID: make(map[*AID]iActor),
52+
actorMapByNodeName: make(map[string]iActor),
53+
nowActorID: 0,
54+
}
55+
return d
56+
}
57+
58+
func (as *ActorSystem) startActor(receiver IActorReceiver) iActor {
59+
actor := &Actor{}
60+
61+
as.mutex.Lock()
62+
defer as.mutex.Unlock()
63+
64+
aid := as.createAID(receiver.GetNodeName())
65+
actor.start(receiver, aid)
66+
as.actorMapByAID[aid] = actor
67+
as.actorMapByNodeName[receiver.GetNodeName()] = actor
68+
69+
return actor
70+
}
71+
72+
func (as *ActorSystem) startWebActor(receiver IActorReceiver, nodeName string, address string) iActor {
73+
actor := &WebActor{}
74+
75+
as.mutex.Lock()
76+
defer as.mutex.Unlock()
77+
78+
aid := as.createAID(nodeName)
79+
actor.start(receiver, aid)
80+
as.actorMapByAID[aid] = actor
81+
as.actorMapByNodeName[nodeName] = actor
82+
83+
actor.address = address
84+
actor.client = &http.Client{}
85+
return actor
86+
}
87+
88+
func (as *ActorSystem) createAID(nodeName string) *AID {
89+
id := atomic.AddUint64(&as.nowActorID, 1)
90+
return &AID{NodeName:nodeName, ActorID:id}
91+
}
92+
93+
func (as *ActorSystem) getActorByAIDWithLock(aid *AID) (iActor, error) {
94+
as.mutex.RLock()
95+
defer as.mutex.RUnlock()
96+
97+
actor, ok := as.actorMapByAID[aid]
98+
if !ok {
99+
return nil, fmt.Errorf("%s", "Not Found Actor")
100+
}
101+
return actor, nil
102+
}
103+
104+
func (d *ActorSystem) getActorByNodeNameWithLock(nodeName string) (iActor, error) {
105+
d.mutex.RLock()
106+
defer d.mutex.RUnlock()
107+
108+
actor, ok := d.actorMapByNodeName[nodeName]
109+
if !ok {
110+
return nil, fmt.Errorf("%s", "Not Found Actor")
111+
}
112+
return actor, nil
113+
}
114+
115+
func (as *ActorSystem) createRequest(ac iActor, function interface{}, args ...interface{}) *Request {
116+
117+
118+
req := &Request{NodeName:ac.GetNodeName()}
119+
120+
v := reflect.ValueOf(function)
121+
if v.Kind() == reflect.Func {
122+
funcFullName := runtime.FuncForPC(reflect.ValueOf(function).Pointer()).Name()
123+
fmt.Println(funcFullName)
124+
tokens := strings.Split(funcFullName, ".")
125+
req.FuncName = tokens[len(tokens)-1]
126+
} else {
127+
req.FuncName = v.String()
128+
}
129+
130+
req.Args = args
131+
return req
132+
}
133+
134+
func (as *ActorSystem) handleRemoteCall(req *Request, res *Response) error {
135+
ac, acErr := as.getActorByNodeNameWithLock(req.NodeName)
136+
if acErr != nil {
137+
res.Err = acErr
138+
return acErr
139+
}
140+
fn, fnErr := as.findFunc(ac, req.FuncName)
141+
if fnErr != nil {
142+
res.Err = fnErr
143+
return fnErr
144+
}
145+
rtn, callErr := ac.call(fn, req.Args...)
146+
res.Results = rtn
147+
res.Err = callErr
148+
return callErr
149+
}
150+
151+
func (as *ActorSystem) findFunc(ac iActor, funcName string) (interface{}, error) {
152+
t := ac.getReceiver().Type()
153+
method, ok := t.MethodByName(funcName)
154+
if !ok {
155+
return nil, fmt.Errorf("%s", "Not Found Func")
156+
}
157+
fn := method.Func.Interface()
158+
return fn, nil
159+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package actor
2+
3+
import "reflect"
4+
5+
type ActorCall struct {
6+
Function reflect.Value
7+
Args []reflect.Value
8+
Results []reflect.Value
9+
Done chan *ActorCall
10+
Error error
11+
}
12+
13+
func (c ActorCall) GetResults() ([]interface{}, error) {
14+
if c.Error != nil {
15+
return nil, c.Error
16+
}
17+
values := c.Results
18+
19+
var rtnResults []interface{}
20+
var err error
21+
for _, x := range values {
22+
itf := x.Interface()
23+
errorType := reflect.TypeOf((*error)(nil)).Elem()
24+
25+
switch x.Type() {
26+
case errorType:
27+
if castingErr, ok := itf.(error); ok && castingErr != nil {
28+
err = x.Interface().(error)
29+
}
30+
default:
31+
rtnResults = append(rtnResults, itf)
32+
}
33+
}
34+
return rtnResults, err
35+
}

0 commit comments

Comments
 (0)