本文整理汇总了Golang中gk/gkerr.GkErrDef.String方法的典型用法代码示例。如果您正苦于以下问题:Golang GkErrDef.String方法的具体用法?Golang GkErrDef.String怎么用?Golang GkErrDef.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gk/gkerr.GkErrDef
的用法示例。
在下文中一共展示了GkErrDef.String方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LoginServerStart
func LoginServerStart() {
var fileName *string = flag.String("config", "", "config file name")
var loginConfig loginConfigDef
var gkErr *gkerr.GkErrDef
flag.Parse()
if *fileName == "" {
flag.PrintDefaults()
return
}
loginConfig, gkErr = loadConfigFile(*fileName)
if gkErr != nil {
fmt.Printf("error before log setup %s\n", gkErr.String())
return
}
gklog.LogInit(loginConfig.LogDir)
gkErr = loginConfig.loginInit()
if gkErr != nil {
gklog.LogGkErr("loginConfig.loginInit", gkErr)
return
}
address := fmt.Sprintf(":%d", loginConfig.Port)
http.ListenAndServe(address, &loginConfig)
}
示例2: logAll
func logAll(level int, message string, argErr error, argGkErr *gkerr.GkErrDef) {
if _logDir == "" {
fmt.Printf("missing call to gklog.LogInit()\n")
return
}
var levelString string = "Unknown"
switch level {
case _trace:
levelString = "Trace"
case _error:
levelString = "Error"
}
var fileName string
var file *os.File
var err error
now := time.Now()
dateName := fmt.Sprintf("%04d_%02d_%02d", now.Year(), now.Month(), now.Day())
timeStamp := fmt.Sprintf("%02d %02d %02d:%02d:%02d.%02d", now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), now.Nanosecond()/10000000.0)
fileName = _logDir + string(os.PathSeparator) + dateName + _logSuffix
file, err = os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
fmt.Printf("could not open output log file: %s\n", fileName)
return
}
defer file.Close()
totalMessage := timeStamp + " " + levelString + " " + message
if err != nil {
totalMessage = totalMessage + " " + fmt.Sprintf("[%v]", err)
}
if argGkErr != nil {
totalMessage = totalMessage + " <" + argGkErr.String() + ">"
}
totalMessage = totalMessage + "\n"
_, err = file.Write([]byte(totalMessage))
if err != nil {
fmt.Printf("could not write log file: %s\n", fileName)
return
}
}
示例3: testSvgHighLevel
func testSvgHighLevel(t *testing.T) {
var gkErr *gkerr.GkErrDef
var inputData []byte = []byte(svgInputData1)
var result []byte
result, gkErr = FixSvgData(inputData, "pre")
if gkErr != nil {
t.Logf("FixSvgData failure " + gkErr.String())
t.Fail()
}
if string(result) != svgOutputData1 {
t.Logf("FixSvgData did not match in: " + svgInputData1 + "\n out: " + string(result) + "\n exp: " + svgOutputData1 + "\n")
t.Fail()
}
}
示例4: main
func main() {
var inputFileName *string = flag.String("in", "", "svg input filename")
var outputFileName *string = flag.String("out", "", "svg output filename")
flag.Parse()
if (*inputFileName == "") || (*outputFileName == "") {
flag.PrintDefaults()
return
}
var inputData []byte
var err error
inputData, err = readSvgData(*inputFileName)
if err != nil {
fmt.Printf("error reading file: %v\n", err)
return
}
var gkErr *gkerr.GkErrDef
var index int
index = strings.LastIndex(*inputFileName, "/")
var prefix string
prefix = (*inputFileName)[index+1:]
prefix = prefix[:len(prefix)-4]
var outputData []byte
outputData, gkErr = gksvg.FixSvgData(inputData, prefix)
if gkErr != nil {
fmt.Printf("error fixing svg file: %s\n", gkErr.String())
return
}
err = writeSvgData(*outputFileName, outputData)
if err != nil {
fmt.Printf("error writing file: %v\n", err)
return
}
}
示例5: testSvgMidLevel
func testSvgMidLevel(t *testing.T) {
var result string
var gkErr *gkerr.GkErrDef
var idMap map[string]string = make(map[string]string)
var space, name, value string
idMap["id1"] = "new_id1"
idMap["id2"] = "new_id2"
name = "href"
space = "xlink"
value = "#id1"
result, gkErr = substituteOneAttributeId(idMap, space, name, value)
if gkErr != nil {
t.Logf("gkErr on substituteOneAttributeId")
t.Fail()
}
if result != "#new_id1" {
t.Logf("invalid result on substituteOneAttibuteId")
t.Fail()
}
name = "style"
space = ""
value = "fill:url(#id2);fill-opacity:1"
result, gkErr = substituteOneAttributeId(idMap, space, name, value)
if gkErr != nil {
t.Logf("gkErr on substituteOneAttributeId " + gkErr.String())
t.Fail()
}
if result != "fill:url(#new_id2);fill-opacity:1" {
t.Logf("invalid result on substituteOneAttibuteId " + result)
t.Fail()
}
name = "style"
space = ""
value = "stroke:none;fill-opacity:1"
result, gkErr = substituteOneAttributeId(idMap, space, name, value)
if gkErr != nil {
t.Logf("gkErr on substituteOneAttributeId " + gkErr.String())
t.Fail()
}
if result != "stroke:none;fill-opacity:1" {
t.Logf("invalid result on substituteOneAttibuteId " + result)
t.Fail()
}
idMap = make(map[string]string)
idMap["linearGradient9986-0-1-3-1-1"] = "new_linearGradient9986-0-1-3-1-1"
idMap["filter8705-8-7-6-6-6-1"] = "new_filter8705-8-7-6-6-6-1"
name = "style"
space = ""
value = "opacity:0.6;fill:url(#linearGradient9986-0-1-3-1-1);fill-opacity:1;filter:url(#filter8705-8-7-6-6-6-1)"
result, gkErr = substituteOneAttributeId(idMap, space, name, value)
if gkErr != nil {
t.Logf("gkErr on substituteOneAttributeId " + gkErr.String())
t.Fail()
}
if result != "opacity:0.6;fill:url(#new_linearGradient9986-0-1-3-1-1);fill-opacity:1;filter:url(#new_filter8705-8-7-6-6-6-1)" {
t.Logf("invalid result on substituteOneAttibuteId " + result)
t.Fail()
}
}
示例6: testPopulateFromMessage
func testPopulateFromMessage(t *testing.T) {
// var command string
// var jsonData []byte
// var data []byte
var gkErr *gkerr.GkErrDef
var message []byte
var messageFromClient *MessageFromClientDef
var sessionId string = "test"
message = []byte("com~{\"name\":\"value\"}~data")
messageFromClient = new(MessageFromClientDef)
gkErr = messageFromClient.PopulateFromMessage(sessionId, message)
if gkErr != nil {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if messageFromClient.Command != "com" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if string(messageFromClient.JsonData) != "{\"name\":\"value\"}" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if string(messageFromClient.data) != "data" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
message = []byte("com~{\"name\":\"value\"}~")
messageFromClient = new(MessageFromClientDef)
gkErr = messageFromClient.PopulateFromMessage(sessionId, message)
if gkErr != nil {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if messageFromClient.Command != "com" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if string(messageFromClient.JsonData) != "{\"name\":\"value\"}" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if string(messageFromClient.data) != "" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
message = []byte("commandOnly~~")
messageFromClient = new(MessageFromClientDef)
gkErr = messageFromClient.PopulateFromMessage(sessionId, message)
if gkErr != nil {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if messageFromClient.Command != "commandOnly" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if string(messageFromClient.JsonData) != "" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
if string(messageFromClient.data) != "" {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data) + " gkErr: " + gkErr.String())
t.Fail()
}
message = []byte("com~{\"name\":\"value\"}data")
messageFromClient = new(MessageFromClientDef)
gkErr = messageFromClient.PopulateFromMessage(sessionId, message)
if gkErr == nil {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data))
t.Fail()
}
message = []byte("com{\"name\":\"value\"}data")
messageFromClient = new(MessageFromClientDef)
gkErr = messageFromClient.PopulateFromMessage(sessionId, message)
if gkErr == nil {
t.Logf("PopulateFromMessage message: " + string(message) + " jsonData: " + string(messageFromClient.JsonData) + " data: " + string(messageFromClient.data))
t.Fail()
}
}
示例7: GameServerStart
func GameServerStart() {
var fileName *string = flag.String("config", "", "config file name")
var gameConfig *config.GameConfigDef
var gkErr *gkerr.GkErrDef
flag.Parse()
if *fileName == "" {
flag.PrintDefaults()
return
}
gameConfig, gkErr = config.LoadConfigFile(*fileName)
if gkErr != nil {
fmt.Print(gkErr.String())
return
}
gklog.LogInit(gameConfig.LogDir)
var randContext *gkrand.GkRandContextDef
var persistenceContext *persistence.PersistenceContextDef
var tokenContext *tokenContextDef
var sessionContext *ses.SessionContextDef
var httpContext *httpContextDef
randContext = gkrand.NewGkRandContext()
persistenceContext, gkErr = persistence.NewPersistenceContext(gameConfig)
if gkErr != nil {
gklog.LogGkErr("persistence.NewPersisenceContext", gkErr)
return
}
tokenContext = NewTokenContext(gameConfig, randContext, sessionContext)
sessionContext = ses.NewSessionContext(randContext)
httpContext = NewHttpContext(gameConfig, persistenceContext, sessionContext, tokenContext)
gkErr = httpContext.gameInit()
if gkErr != nil {
gklog.LogGkErr("httpContext.gameInit", gkErr)
return
}
gkErr = tokenContext.gameInit()
if gkErr != nil {
gklog.LogGkErr("tokenContext.gameInit", gkErr)
return
}
gklog.LogTrace("game server started")
var wsContext *ws.WsContextDef
var fieldContext *field.FieldContextDef
fieldContext, gkErr = field.NewFieldContext(gameConfig.AvatarSvgDir, gameConfig.TerrainSvgDir, sessionContext, persistenceContext)
if gkErr != nil {
gklog.LogGkErr("field.NewFieldContext", gkErr)
return
}
wsContext = ws.NewWsContext(gameConfig, sessionContext, fieldContext)
ws.SetGlobalWsContext(wsContext)
go fieldContext.StartFieldHandler()
httpAddress := fmt.Sprintf(":%d", gameConfig.HttpPort)
tokenAddress := fmt.Sprintf(":%d", gameConfig.TokenPort)
var err error
go func() {
err = http.ListenAndServe(tokenAddress, tokenContext)
if err != nil {
gkErr = gkerr.GenGkErr("http.ListenAndServer token", err, ERROR_ID_TOKEN_SERVER_START)
gklog.LogGkErr("", gkErr)
return
}
gklog.LogTrace("token listener ended, this is probably bad")
}()
go func() {
err = http.ListenAndServe(httpAddress, httpContext)
if err != nil {
gkErr = gkerr.GenGkErr("http.ListenAndServer http", err, ERROR_ID_HTTP_SERVER_START)
gklog.LogGkErr("", gkErr)
return
}
gklog.LogTrace("http listener ended, this is probably bad")
}()
go func() {
websocketAddress := fmt.Sprintf(":%d", gameConfig.WebsocketPort)
gklog.LogTrace("starting web socket listener")
if gameConfig.CertificatePath == "" {
err = http.ListenAndServe(websocketAddress, websocket.Handler(ws.WebsocketHandler))
} else {
err = http.ListenAndServeTLS(websocketAddress, gameConfig.CertificatePath, gameConfig.PrivateKeyPath, websocket.Handler(ws.WebsocketHandler))
}
if err != nil {
//.........这里部分代码省略.........