예제 #1
0
파일: codegen.go 프로젝트: gsrpc/gsrpc
// NewCodeGen .
func NewCodeGen(rootpath string, skips []string) (gslang.Visitor, error) {

	codeGen := &_CodeGen{
		Log:      gslogger.Get("gen4go"),
		rootpath: rootpath,
		prefix:   make(map[string]string),
	}

	for _, skip := range skips {
		exp, err := regexp.Compile(skip)

		if err != nil {
			return nil, gserrors.Newf(err, "invalid skip regex string :%s", skip)
		}

		codeGen.skips = append(codeGen.skips, exp)
	}

	funcs := template.FuncMap{
		"title":           codeGen.title,
		"title2":          strings.Title,
		"enumFields":      codeGen.enumFields,
		"typeName":        codeGen.typeName,
		"enumRead":        codeGen.enumRead,
		"enumWrite":       codeGen.enumWrite,
		"fieldDecl":       codeGen.fieldDecl,
		"defaultVal":      codeGen.defaultVal,
		"marshalField":    codeGen.marshalField,
		"unmarshalField":  codeGen.unmarshalField,
		"methodDecl":      codeGen.methodDecl,
		"rpcMethodDecl":   codeGen.rpcMethodDecl,
		"unmarshalParam":  codeGen.unmarshalParam,
		"marshalParam":    codeGen.marshalParam,
		"methodCall":      codeGen.methodCall,
		"marshalReturn":   codeGen.marshalReturn,
		"unmarshalReturn": codeGen.unmarshalReturn,
		"notVoid":         gslang.NotVoid,
		"isPOD":           gslang.IsPOD,
		"isAsync":         gslang.IsAsync,
		"isException":     gslang.IsException,
		"enumSize":        gslang.EnumSize,
		"enumType": func(typeDecl ast.Type) string {
			return builtin[gslang.EnumType(typeDecl)]
		},
		"builtin":       gslang.IsBuiltin,
		"marshalParams": codeGen.marshalParams,
		"callback":      codeGen.callback,
		"tagValue":      codeGen.tagValue,
	}

	tpl, err := template.New("t4objc").Funcs(funcs).Parse(t4objc)

	if err != nil {
		return nil, err
	}

	codeGen.tpl = tpl

	return codeGen, nil
}
예제 #2
0
파일: handler.go 프로젝트: gsrpc/gorpc
func newContext(name string, handler Handler, pipeline *_Pipeline, prev *_Context) (*_Context, error) {
	context := &_Context{
		Log:      gslogger.Get("handler-context"),
		name:     name,
		handler:  handler,
		pipeline: pipeline,
		prev:     prev,
		state:    handlerUnregister,
	}

	context.shared, _ = handler.(SharedHandler)

	err := context.handler.Register(context)

	if err != nil {
		return nil, err
	}

	if context.prev != nil {
		context.prev.next = context
	}

	context.state = handlerRegister

	return context, nil

}
예제 #3
0
파일: datasource.go 프로젝트: gschat/tsdb
// Open create new tsdb with root directory
func Open(filepath string) (DataSource, error) {

	if !fs.Exists(filepath) {
		err := os.MkdirAll(filepath, 0644)
		if err != nil {
			return nil, err
		}
	}

	idgen, err := newSEQIDGen(filepath)

	if err != nil {
		return nil, err
	}

	persistence, err := newDB(filepath)

	if err != nil {
		return nil, err
	}

	return &_DataSource{
		Log:         gslogger.Get("tsdb"),
		SEQIDGen:    idgen,
		Persistence: persistence,
		cached:      make(map[string]*_Cached),
		cachedsize:  gsconfig.Int("tsdb.cached.size", 1024),
	}, nil
}
예제 #4
0
파일: client.go 프로젝트: gsdocker/gsproxy
func (proxy *_Proxy) newClientHandler() gorpc.Handler {

	return &_Client{
		Log:     gslogger.Get("gsproxy-client"),
		context: proxy,
	}
}
예제 #5
0
파일: compiler.go 프로젝트: gsrpc/gslang
// Visit visit ast tree
func (compiler *Compiler) Visit(codeGen Visitor) (err error) {

	defer func() {
		if e := recover(); e != nil {

			gserr, ok := e.(gserrors.GSError)

			if ok {
				err = gserr
			} else {
				err = gserrors.Newf(e.(error), "catch unknown error")
			}
		}
	}()

	gen := &_Visitor{
		Log:      gslogger.Get("codegen"),
		codeGen:  codeGen,
		module:   compiler.module,
		compiler: compiler,
	}

	gen.visit()

	return
}
예제 #6
0
파일: pipeline.go 프로젝트: gsrpc/gorpc
// Build create new Pipeline
func (builder *PipelineBuilder) Build(name string) (Pipeline, error) {

	pipeline := &_Pipeline{
		Log:        gslogger.Get("pipeline"),
		name:       name,
		timewheel:  builder.timewheel,
		sendcached: make(chan func() (*Message, error), builder.cachedsize),
		closedflag: make(chan bool),
	}

	close(pipeline.closedflag)

	pipeline.Sink = NewSink(name, pipeline, pipeline.TimeWheel(), builder.timeout)

	var err error

	for i, f := range builder.handlers {
		pipeline.tail, err = newContext(builder.names[i], f(), pipeline, pipeline.tail)

		if pipeline.header == nil {
			pipeline.header = pipeline.tail
		}

		if err != nil {
			return nil, err
		}
	}

	return pipeline, err
}
예제 #7
0
파일: heartbeat.go 프로젝트: gsrpc/gorpc
// NewHeartbeatHandler create new heartbeat handler
func NewHeartbeatHandler(timeout time.Duration) gorpc.Handler {
	return &_HeartbeatHandler{
		Log:       gslogger.Get("heartbeat"),
		timeout:   timeout,
		timestamp: time.Now(),
	}
}
예제 #8
0
파일: runner.go 프로젝트: gsdocker/gsrunner
// New create new gsdocker runner
func New(name string) Runner {
	runner := &_Runner{
		Log:              gslogger.Get(name),
		flagString:       make(map[string]*string),
		flagInt:          make(map[string]*int64),
		flagUint:         make(map[string]*uint64),
		flagFloat32:      make(map[string]*float64),
		flagFloat64:      make(map[string]*float64),
		flagSecond:       make(map[string]*uint64),
		flagMilliseconds: make(map[string]*uint64),
		fullname:         make(map[string]string),
	}

	runner.FlagString(
		"log", "gsrunner.log", "", "the gsrunner log root path",
	).FlagString(
		"level", "gsrunner.log.level", "", "the gsrunner log level",
	).FlagString(
		"pprof", "gsrunner.pprof", "", "set gsrunner pprof listen address",
	).FlagString(
		"config", "gsrunner.config", "", "set gsrunner config file",
	).FlagString(
		"registry", "gsrunner.registry", "", "set the rpc services registry file",
	)

	return runner
}
예제 #9
0
파일: eval.go 프로젝트: gsrpc/gslang
func newEval(errorHandler ErrorHandler, module *ast.Module) Eval {
	return &_Eval{
		Log:          gslogger.Get("eval"),
		module:       module,
		errorHandler: errorHandler,
	}
}
예제 #10
0
파일: dh.go 프로젝트: gsrpc/gorpc
// NewCryptoClient .
func NewCryptoClient(device *gorpc.Device, dhKey *DHKey) gorpc.Handler {
	return &_CryptoClient{
		Log:    gslogger.Get("crpyto-client"),
		dhKey:  dhKey,
		device: device,
	}
}
예제 #11
0
func (proxy *_Proxy) newTunnelServer() gorpc.Handler {
	return &_TunnelServerHandler{
		Log:   gslogger.Get("agent-server-tunnel"),
		proxy: proxy,
		id:    proxy.tunnelID(),
	}
}
예제 #12
0
파일: tunnel.go 프로젝트: gsdocker/gsproxy
func (system *_System) newTunnelClient(name string) gorpc.Handler {
	return &_TunnelClient{
		Log:     gslogger.Get("gsagent-tunnel"),
		name:    name,
		system:  system,
		timeout: system.timeout,
	}
}
예제 #13
0
파일: acceptor.go 프로젝트: gsrpc/gorpc
// NewAcceptor create new server channel acceptor
func NewAcceptor(name string, builder *PipelineBuilder) *Acceptor {
	return &Acceptor{
		Log:     gslogger.Get(name),
		builder: builder,
		timeout: gsconfig.Seconds("timeout", 5),
		name:    name,
	}
}
예제 #14
0
func (proxy *_Proxy) newTransProxyHandler() gorpc.Handler {
	return &_TransProxyHandler{
		Log:     gslogger.Get("trans-proxy"),
		proxy:   proxy,
		servers: make(map[uint16]Server),
		tunnels: make(map[byte]Server),
	}
}
예제 #15
0
파일: main.go 프로젝트: gsrpc/gsrpc
func main() {
	gslogger.Console("$content", "2006-01-02 15:04:05.999999")
	gslogger.NewFlags(gslogger.ERROR | gslogger.WARN | gslogger.INFO)
	log := gslogger.Get("gsrpc")

	defer func() {
		if e := recover(); e != nil {
			log.E("%s", e)
		}

		gslogger.Join()
	}()

	flag.Parse()

	*output, _ = filepath.Abs(*output)

	log.I("Start gsRPC With Target Language(%s)", *lang)

	codegenF, ok := langs[*lang]

	if !ok {
		log.E("unknown gsrpc object language :%s", *lang)
		os.Exit(1)
	}

	codegen, err := codegenF(*output, []string{"github.com/gsrpc/gslang"})

	if err != nil {
		gserrors.Panicf(err, "create language(%s) codegen error", *lang)
	}

	compiler := gslang.NewCompiler("gsrpc", gslang.HandleError(func(err *gslang.Error) {
		gserrors.Panicf(err.Orignal, "parse %s error\n\t%s", err.Start, err.Text)
	}))

	for _, file := range flag.Args() {
		log.I("Compile gsLang File :%s", file)
		if err := compiler.Compile(file); err != nil {
			gserrors.Panicf(err, "compile %s error", file)
		}
	}

	log.I("Link ...")
	err = compiler.Link()

	if err != nil {
		gserrors.Panicf(err, "link error")
	}

	log.I("Output Directory :%s", *output)

	if err := compiler.Visit(codegen); err != nil {
		gserrors.Panicf(err, "generate language codes(%s) error", *lang)
	}

	log.I("Run gsRPC Compile -- Success")
}
예제 #16
0
파일: parser.go 프로젝트: gsrpc/gslang
func (compiler *Compiler) parse(lexer *lexer.Lexer, errorHandler ErrorHandler) *ast.Script {

	return (&Parser{
		Log:          gslogger.Get("parser"),
		lexer:        lexer,
		script:       compiler.module.NewScript(lexer.String()),
		errorHandler: errorHandler,
	}).parse()
}
예제 #17
0
파일: gsproxy.go 프로젝트: gsdocker/gsproxy
// Build .
func (builder *ProxyBuilder) Build(name string) Context {

	proxy := &_Proxy{
		Log:     gslogger.Get("gsproxy"),
		proxy:   builder.proxy,
		clients: make(map[string]*_Client),
		name:    name,
		tunnels: make(map[byte]byte),
	}

	proxy.frontend = gorpc.NewAcceptor(
		fmt.Sprintf("%s.frontend", name),
		gorpc.BuildPipeline(time.Millisecond*10).Handler(
			"gsproxy-profile",
			gorpc.ProfileHandler,
		).Handler(
			"gsproxy-hb",
			func() gorpc.Handler {
				return handler.NewHeartbeatHandler(builder.timeout)
			},
		).Handler(
			"gsproxy-dh",
			func() gorpc.Handler {
				return handler.NewCryptoServer(builder.dhkeyResolver)
			},
		).Handler(
			transProxyHandler,
			proxy.newTransProxyHandler,
		).Handler(
			"gsproxy-client",
			proxy.newClientHandler,
		),
	)

	proxy.backend = gorpc.NewAcceptor(
		fmt.Sprintf("%s.backend", name),
		gorpc.BuildPipeline(time.Millisecond*10).Handler(
			tunnelHandler,
			proxy.newTunnelServer,
		),
	)

	go func() {
		if err := gorpc.TCPListen(proxy.backend, builder.laddrE); err != nil {
			proxy.E("start agent backend error :%s", err)
		}
	}()

	go func() {
		if err := gorpc.TCPListen(proxy.frontend, builder.laddrF); err != nil {
			proxy.E("start agent frontend error :%s", err)
		}
	}()

	return proxy
}
예제 #18
0
파일: sink.go 프로젝트: gsrpc/gorpc
// NewSink .
func NewSink(name string, channel MessageChannel, timeWheel *timer.Wheel, timeout time.Duration) Sink {
	return &_Sink{
		Log:         gslogger.Get("sink"),
		name:        name,
		timeout:     timeout,
		dispatchers: make(map[uint16]Dispatcher),
		promises:    make(map[uint32]Promise),
		channel:     channel,
		timeWheel:   timeWheel,
	}
}
예제 #19
0
파일: compiler.go 프로젝트: gsrpc/gslang
// NewCompiler .
func NewCompiler(name string, errorHandler ErrorHandler) *Compiler {

	module := ast.NewModule(name)

	return &Compiler{
		Log:          gslogger.Get("compiler"),
		module:       module,
		errorHandler: errorHandler,
		eval:         newEval(errorHandler, module),
	}

}
예제 #20
0
파일: lexer.go 프로젝트: gsrpc/gslang
//NewLexer create new gslang lexer
func NewLexer(tag string, reader io.Reader) *Lexer {
	return &Lexer{
		Log:    gslogger.Get("gslang[lexer]"),
		reader: bufio.NewReader(reader),
		ws:     1<<'\t' | 1<<'\n' | 1<<'\r' | 1<<' ',
		position: Position{
			FileName: tag,
			Lines:    1,
			Column:   1,
		},
		curr: rune(TokenEOF),
	}
}
예제 #21
0
파일: id.go 프로젝트: gschat/tsdb
func newSEQIDGen(dir string) (*_SEQIDGen, error) {

	db, err := leveldb.OpenFile(filepath.Join(dir, "id.db"), nil)

	if err != nil {
		return nil, err
	}

	return &_SEQIDGen{
		Log: gslogger.Get("tsdb-id"),
		db:  db,
	}, nil
}
예제 #22
0
파일: storage.go 프로젝트: gschat/tsdb
func newDB(dir string) (Persistence, error) {
	db, err := leveldb.OpenFile(filepath.Join(dir, "keyspace.db"), nil)

	if err != nil {
		return nil, err
	}

	return &_DB{
		Log:      gslogger.Get("tsdb.backend"),
		db:       db,
		storages: make(map[string]Storage),
		valen:    gsconfig.Int("tsdb.value.length", 1024),
	}, nil
}
예제 #23
0
파일: codegen.go 프로젝트: gsrpc/gsrpc
// NewCodeGen .
func NewCodeGen(rootpath string, skips []string) (gslang.Visitor, error) {

	codeGen := &_CodeGen{
		Log:      gslogger.Get("gen4go"),
		rootpath: rootpath,
	}

	for _, skip := range skips {
		exp, err := regexp.Compile(skip)

		if err != nil {
			return nil, gserrors.Newf(err, "invalid skip regex string :%s", skip)
		}

		codeGen.skips = append(codeGen.skips, exp)
	}

	funcs := template.FuncMap{
		"title": strings.Title,
		"enumType": func(typeDecl ast.Type) string {
			return builtin[gslang.EnumType(typeDecl)]
		},
		"notVoid":     gslang.NotVoid,
		"isPOD":       gslang.IsPOD,
		"isAsync":     gslang.IsAsync,
		"isException": gslang.IsException,
		"enumSize":    gslang.EnumSize,
		"builtin":     gslang.IsBuiltin,
		"typeName":    codeGen.typeName,
		"defaultVal":  codeGen.defaultVal,
		"readType":    codeGen.readType,
		"writeType":   codeGen.writeType,
		"params":      codeGen.params,
		"returnParam": codeGen.returnParam,
		"callArgs":    codeGen.callArgs,
		"returnArgs":  codeGen.returnArgs,
		"tagValue":    codeGen.tagValue,
	}

	tpl, err := template.New("gen4go").Funcs(funcs).Parse(tpl4go)

	if err != nil {
		return nil, err
	}

	codeGen.tpl = tpl

	return codeGen, nil
}
예제 #24
0
파일: client.go 프로젝트: gsrpc/gorpc
// Build create new client
func (builder *ClientBuilder) Build(name string, F ConnectF) (Client, error) {
	client := &_Client{
		Log:   gslogger.Get(fmt.Sprintf("%s.%s", builder.name, name)),
		name:  fmt.Sprintf("%s.%s", builder.name, name),
		f:     F,
		state: uint32(StateDisconnect),
	}

	client.Log = gslogger.Get(name)

	var err error

	client.pipeline, err = builder.builder.Build(name)

	if err != nil {
		return nil, err
	}

	client.pipeline.Active()

	client.doconnect()

	return client, nil
}
예제 #25
0
파일: linker.go 프로젝트: gsrpc/gslang
// Link do sematic paring and type link
func (compiler *Compiler) Link() (err error) {

	defer func() {
		if e := recover(); e != nil {
			err = e.(error)
		}
	}()

	linker := &_Linker{
		Log:          gslogger.Get("linker"),
		types:        make(map[string]ast.Type),
		errorHandler: compiler.errorHandler,
		compiler:     compiler,
	}

	compiler.module.Foreach(func(script *ast.Script) bool {
		linker.createSymbolTable(script)
		return true
	})

	compiler.module.Types = linker.types

	compiler.module.Foreach(func(script *ast.Script) bool {
		linker.linkTypes(script)
		return true
	})

	compiler.module.Foreach(func(script *ast.Script) bool {

		script.TypeForeach(func(gslangType ast.Type) {

			linker.checkAnnotation(script, gslangType)
		})

		return true
	})

	return
}
예제 #26
0
파일: codegen.go 프로젝트: gsrpc/gsrpc
// NewCodeGen .
func NewCodeGen(rootpath string, skips []string) (gslang.Visitor, error) {

	codeGen := &_CodeGen{
		Log:      gslogger.Get("gen4go"),
		rootpath: rootpath,
	}

	for _, skip := range skips {
		exp, err := regexp.Compile(skip)

		if err != nil {
			return nil, gserrors.Newf(err, "invalid skip regex string :%s", skip)
		}

		codeGen.skips = append(codeGen.skips, exp)
	}

	funcs := template.FuncMap{
		"exception": exception,
		"title":     strings.Title,
		"tableName": func(typeDecl ast.Type) string {
			if gslang.IsException(typeDecl) {
				return exception(strings.Title(typeDecl.Name()))
			}

			return strings.Title(typeDecl.Name())
		},
		"methodName":  methodName,
		"fieldName":   fieldname,
		"enumFields":  codeGen.enumFields,
		"notVoid":     gslang.NotVoid,
		"isPOD":       gslang.IsPOD,
		"isAsync":     gslang.IsAsync,
		"isException": gslang.IsException,
		"enumSize":    gslang.EnumSize,
		"enumType": func(typeDecl ast.Type) string {
			return builtin[gslang.EnumType(typeDecl)]
		},
		"builtin":         gslang.IsBuiltin,
		"typeName":        codeGen.typeName,
		"objTypeName":     codeGen.objTypeName,
		"defaultVal":      codeGen.defaultVal,
		"readType":        codeGen.readType,
		"writeType":       codeGen.writeType,
		"params":          codeGen.params,
		"returnParam":     codeGen.returnParam,
		"callArgs":        codeGen.callArgs,
		"returnArgs":      codeGen.returnArgs,
		"marshalField":    codeGen.marshalfield,
		"unmarshalField":  codeGen.unmarshalfield,
		"unmarshalParam":  codeGen.unmarshalParam,
		"methodcall":      codeGen.methodcall,
		"marshalParam":    codeGen.marshalParam,
		"marshalReturn":   codeGen.marshalReturn,
		"methodRPC":       codeGen.methodRPC,
		"marshalParams":   codeGen.marshalParams,
		"callback":        codeGen.callback,
		"unmarshalReturn": codeGen.unmarshalReturn,
		"constructor":     codeGen.constructor,
		"tagValue":        codeGen.tagValue,
	}

	tpl, err := template.New("t4java").Funcs(funcs).Parse(t4java)

	if err != nil {
		return nil, err
	}

	codeGen.tpl = tpl

	return codeGen, nil
}
예제 #27
0
파일: gslang_test.go 프로젝트: gsrpc/gslang
package test

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"testing"

	"github.com/gsdocker/gserrors"
	"github.com/gsdocker/gslogger"
	"github.com/gsrpc/gslang"
	"github.com/gsrpc/gslang/lexer"
)

var (
	log = gslogger.Get("gslang")
)

func TestToken(t *testing.T) {

	content, err := ioutil.ReadFile("test.gs")

	if err != nil {
		t.Fatal(err)
	}

	tokenizer := lexer.NewLexer("mem", bytes.NewBuffer(content))

	for {

		token, err := tokenizer.Next()
예제 #28
0
파일: imserver.go 프로젝트: gschat/gschat
// NewIMServer create new im server
func NewIMServer() gsactor.AgentSystem {
	return &_IMServer{
		Log: gslogger.Get("imserver"),
	}
}
예제 #29
0
파일: rpc_test.go 프로젝트: gsrpc/gorpc
	"net/http"
	"net/url"
	"testing"
	"time"

	"github.com/gorilla/websocket"
	"github.com/gsdocker/gslogger"
	"github.com/gsrpc/gorpc"
	"github.com/gsrpc/gorpc/handler"
)

var G *big.Int

var P *big.Int

var log = gslogger.Get("test")

func init() {
	G, _ = new(big.Int).SetString("6849211231874234332173554215962568648211715948614349192108760170867674332076420634857278025209099493881977517436387566623834457627945222750416199306671083", 0)

	P, _ = new(big.Int).SetString("13196520348498300509170571968898643110806720751219744788129636326922565480984492185368038375211941297871289403061486510064429072584259746910423138674192557", 0)
}

type _MockRESTful struct {
	kv map[string]string //
}

func (mock *_MockRESTful) Put(callSite *gorpc.CallSite, name string, val string) error {
	mock.kv[name] = val

	return nil
예제 #30
0
파일: dh.go 프로젝트: gsrpc/gorpc
// NewCryptoServer .
func NewCryptoServer(resovler DHKeyResolver) gorpc.Handler {
	return &_CryptoServer{
		Log:      gslogger.Get("crpyto-server"),
		resovler: resovler,
	}
}