本文整理汇总了Golang中sc/logger.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Reading
func (c *Connection) Reading() {
c.ws.SetReadLimit(MaxMessageSize)
c.ws.SetReadDeadline(time.Now().Add(PongWait))
for {
_, message, err := c.ws.ReadMessage()
if err != nil {
if err != io.EOF && err.Error() != "websocket: close 1005 " {
logger.Error(errors.New(err))
}
break
}
smessage := string(message)
if smessage == `{"command":"ping"}` {
c.Send(`{"command":"pong"}`)
continue
} else {
logger.String(fmt.Sprintf("message: %v", smessage))
}
commandDetector := CommandDetector{}
err = json.Unmarshal(message, &commandDetector)
if err != nil {
logger.Error(errors.New(err))
continue
}
generator, ok := c.commands[commandDetector.Command]
if ok {
command := generator(c, c.commandContext)
go timeWrapper(commandDetector.Command, command, message)
}
}
if c.SessionExists {
if c.Session.IsAuth {
user, _ := model2_user.Get(c.Session.UserUUID)
if user != nil {
user.Unlock()
}
}
c.Session.Unlock()
}
}
示例2: Get
func Get(UUID gocql.UUID) *Server {
s := &Server{UUID: UUID, Exists: false}
var row = map[string]interface{}{}
var uuid = UUID.String()
if err := CQLSession.Query(`SELECT * FROM servers where server_uuid = ?`, uuid).MapScan(row); err != nil {
if err != gocql.ErrNotFound {
logger.Error(errors.New(err))
}
return s
}
s.Exists = true
s.IP = row["ip"].(string)
s.Port = uint16(row["port"].(int))
t := time.Now().Unix()
if t-row["live_ts"].(int64) > 10 {
s.Exists = false
}
return s
}
示例3: AddMethod
func (u *Fields) AddMethod(method string, unique string) error {
methodUUID := GetMethodUUID(method, unique)
if err := CQLSession.Query(`insert into idx_users_method_uuid (method, method_uuid, user_uuid) values (?,?,?)`, method, methodUUID, u.UUID).Exec(); err != nil {
logger.Error(errors.New(err))
return err
}
return nil
}
示例4: Reading
func (s *Server) Reading() {
s.ws.SetReadLimit(MaxMessageSize)
s.ws.SetReadDeadline(time.Now().Add(PongWait))
// s.ws.SetPongHandler(func(string) error { s.ws.SetReadDeadline(time.Now().Add(PongWait)); return nil })
for {
_, message, err := s.ws.ReadMessage()
if err != nil {
if err != io.EOF {
logger.Error(errors.New(err))
}
break
}
// logger.String(fmt.Sprintf("star message type %d", mt))
smessage := string(message)
if smessage != `{"command":"pong"}` {
logger.String(fmt.Sprintf("star message: %v", smessage))
}
commandDetector := CommandDetector{}
err = json.Unmarshal(message, &commandDetector)
if err != nil {
logger.Error(errors.New(err))
continue
}
if commandDetector.Command == "answer" {
answer, ok := answers[int(commandDetector.CommandId)]
if ok {
answer <- message
delete(answers, int(commandDetector.CommandId))
}
}
s.ws.SetReadDeadline(time.Now().Add(PongWait))
}
}
示例5: connectionsTreator
func (f *Factory) connectionsTreator() {
pingTicker := time.NewTicker(connection.PingPeriod)
defer func() {
pingTicker.Stop()
}()
for {
select {
case message := <-f.writeChannel:
logger.String("send message: " + message.Message)
go func() {
err := message.Connection.Write(websocket.TextMessage, []byte(message.Message))
if err != nil {
logger.Error(errors.New(err))
message.Connection.Close()
}
}()
case c := <-f.closeChannel:
delete(f.connections, c.Id)
case <-pingTicker.C:
var cs map[uint32]*connection.Connection = make(map[uint32]*connection.Connection)
logger.String("pingTicker.lock")
f.mutex.Lock()
for index, connection := range f.connections {
cs[index] = connection
}
f.mutex.Unlock()
logger.String("pingTicker.unlock")
for _, connection := range f.connections {
go func() {
err := connection.Ping()
if err != nil {
connection.Close()
}
}()
}
// case <-f.closeFactory:
}
}
}
示例6: GetByMethod
func GetByMethod(method string, unique string) (*Fields, error) {
methodUUID := GetMethodUUID(method, unique)
u := &Fields{}
var row = model.Fields{}
if err := CQLSession.Query(`SELECT * FROM idx_users_method_uuid where method = ? and method_uuid = ?`, method, methodUUID).MapScan(row); err != nil {
if err != gocql.ErrNotFound {
logger.Error(errors.New(err))
}
return u, nil
}
u.UUID = row["user_uuid"].(gocql.UUID)
err := u.Load()
return u, err
}
示例7: Send
func (s *Server) Send(message map[string]interface{}) ([]byte, error) {
b, err := json.Marshal(message)
if err != nil {
logger.Error(errors.New(err))
return nil, err
}
logger.String(fmt.Sprintf("star send: %+v", string(b)))
if s.isLocal {
command := message["command"].(string)
logger.String(fmt.Sprintf("isLocal: %s", command))
generator, ok := commands[command]
if ok {
command := generator(localConnection, commandContext)
command.Execute(b)
a := localAnswers[message["command_id"].(int)]
delete(localAnswers, message["command_id"].(int))
return a, nil
}
return nil, nil
}
s.ws.SetWriteDeadline(time.Now().Add(10 * time.Second))
rc := make(chan []byte)
answers[message["command_id"].(int)] = rc
err = s.ws.WriteMessage(websocket.TextMessage, b)
if err != nil {
return nil, err
}
ri := <-rc
return ri, nil
}
示例8: Create
func Create() (*Fields, error) {
var err error
m := &Fields{Exists: false}
for {
m.UUID, err = gocql.RandomUUID()
if err != nil {
return nil, err
}
var row = map[string]interface{}{}
var apply bool
if apply, err = CQLSession.Query(`insert into live_planets (planet_uuid,create_time) values (?,now()) if not exists`, m.UUID).MapScanCAS(row); err != nil {
logger.Error(errors.New(err))
return nil, err
}
if apply {
break
}
}
return m, nil
}
示例9: Pinger
func (s *Server) Pinger() {
pingTicker := time.NewTicker(PingPeriod)
defer func() {
pingTicker.Stop()
}()
for {
select {
case <-pingTicker.C:
s.ws.SetWriteDeadline(time.Now().Add(WriteWait))
if err := s.ws.WriteMessage(websocket.TextMessage, []byte(`{"command":"ping"}`)); err != nil {
logger.Error(errors.New(err))
break
}
}
}
}
示例10: Create
func (p *Player) Create() error {
p.Exists = false
for {
p.UUID = gocql.TimeUUID()
var row = map[string]interface{}{}
var apply bool
var err error
if apply, err = CQLSession.Query(`insert into players (player_uuid,create_time) values (?,now()) if not exists`, p.UUID).MapScanCAS(row); err != nil {
logger.Error(errors.New(err))
return err
}
if apply {
break
}
}
return nil
}
示例11: Create
func (s *Session) Create(remoteAddr string, userAgent string) {
s.Exists = false
for {
s.UUID = gocql.TimeUUID()
var row = model.Fields{}
var apply bool
var err error
if apply, err = CQLSession.Query(`insert into auth_sessions (session_uuid,last_access,create_time, remote_addr, user_agent) values (?,now(),now(),?,?) if not exists`, s.UUID, remoteAddr, userAgent).MapScanCAS(row); err != nil {
logger.Error(errors.New(err))
return
}
if apply {
break
}
}
s.Load()
}
示例12: main
func main() {
log.SetFlags(log.Llongfile)
expvar.Publish("Goroutines", expvar.Func(goroutines))
runtime.GOMAXPROCS(6)
var err *errors.Error
config, err = readConfig()
if err != nil {
// logger.Error(fmt.Sprintf("readConfig - %v", err))
log.Fatal(err)
// log.Fatal("ListenAndServe: ", err)
os.Exit(0)
}
logger.Init(config.Logger.Path)
if config.Daemonize {
flag.Parse()
daemon.AddCommand(daemon.StringFlag(signal, "quit"), syscall.SIGQUIT, termHandler)
daemon.AddCommand(daemon.StringFlag(signal, "stop"), syscall.SIGTERM, termHandler)
daemon.AddCommand(daemon.StringFlag(signal, "reload"), syscall.SIGHUP, reloadHandler)
cntxt := &daemon.Context{
PidFileName: config.PidFilepath,
PidFilePerm: 0644,
LogFileName: config.Logger.Path + "/stdout.log",
LogFilePerm: 0640,
WorkDir: "./",
Umask: 027,
Args: []string{"[spacecraft-online]"},
}
if len(daemon.ActiveFlags()) > 0 {
d, err := cntxt.Search()
if err != nil {
log.Fatalln("Unable send signal to the daemon:", err)
}
daemon.SendCommands(d)
return
}
d, err := cntxt.Reborn()
if err != nil {
log.Fatalln(err)
}
if d != nil {
return
}
defer cntxt.Release()
}
logger.String(fmt.Sprintf("started"))
cluster := gocql.NewCluster(config.Cassandra.IP)
cluster.Keyspace = "sc_2"
cluster.Consistency = 1
session, berr := cluster.CreateSession()
model_server.Init(session)
ip, t := localIP()
if t != nil {
logger.Error(errors.New(t))
os.Exit(0)
}
server := model_server.New(ip, config.Http.Port)
model.Init(server.UUID, session)
server.StartUpdater()
star.SetLocalServer(server)
bdispatcher := buildings.NewDispatcher(config.Buildings.PoolSize)
model2.InstallModels(session,
server.UUID,
model2_auth_session.InstallInfo,
model2_user.InstallInfo,
model2_live_planet.InstallInfo,
model2_building.InstallInfo,
model2_player.InstallInfo)
var connectionFactory = factory.New()
// clients commands
connectionFactory.InstallCommand("auth", cmd_auth.Generator)
connectionFactory.InstallCommand("logout", cmd_logout.Generator)
connectionFactory.InstallCommand("set_section", cmd_set_section.Generator)
connectionFactory.InstallCommand("start", cmd_start.Generator)
connectionFactory.InstallCommand("get_planet", cmd_get_planet.Generator)
connectionFactory.InstallCommand("get_planet_buildings_for_construct", cmd_get_planet_buildings_for_construct.Generator)
connectionFactory.InstallCommand("build", cmd_build.Generator)
// star commands
//.........这里部分代码省略.........
示例13: Load
func (m *Model) Load() error {
var row = Fields{}
m.Exists = false
if err := CQLSession.Query(`SELECT * FROM `+m.TableName+` where `+m.UUIDFieldName+` = ?`, m.UUID).MapScan(row); err != nil {
if err != gocql.ErrNotFound {
logger.Error(errors.New(err))
return err
}
return nil
}
logger.String(fmt.Sprintf("%+v", row))
m.IsLock = row["lock"].(bool)
m.LockServerUUID = row["lock_server_uuid"].(gocql.UUID)
// m.Child.LoadFromMap(row)
modelInfo := getModelInfo(m.Child)
val := r.Indirect(r.ValueOf(m.Child))
for key, value := range row {
var structField r.Value
if info, ok := modelInfo.CQLFields[key]; ok {
structField = val.Field(info.Num)
switch value.(type) {
case nil:
structField.Set(r.ValueOf(info.Zero))
case []gocql.UUID:
switch info.Zero.(type) {
case []*gocql.UUID:
v := value.([]gocql.UUID)
res := []*gocql.UUID{}
for _, item := range v {
res = append(res, &item)
}
structField.Set(r.ValueOf(res))
default:
structField.Set(r.ValueOf(value))
}
case gocql.UUID:
logger.String(fmt.Sprintf("value gocql.UUID for key %s ", key))
switch info.Zero.(type) {
case *gocql.UUID:
logger.String(fmt.Sprintf("assign *gocql.UUID"))
v := value.(gocql.UUID)
if v.String() == "00000000-0000-0000-0000-000000000000" {
// structField.Set(r.ValueOf(nil))
structField.Set(r.ValueOf(info.Zero))
} else {
structField.Set(r.ValueOf(&v))
}
default:
structField.Set(r.ValueOf(value))
}
default:
structField.Set(r.ValueOf(value))
}
// structField.Set(r.ValueOf(value))
}
}
// logger.String(fmt.Sprintf("%+v", m.Child))
m.Exists = true
return nil
}
示例14: Update
func (m *Fields) Update(fields model.Fields) error {
pairs := []string{}
for key, value := range fields {
switch key {
case "UUID":
switch value.(type) {
case nil:
m.UUID = gocql.UUID{}
default:
m.UUID = value.(gocql.UUID)
}
case "IsLock":
switch value.(type) {
case nil:
m.IsLock = false
default:
m.IsLock = value.(bool)
}
case "LockServerUUID":
switch value.(type) {
case nil:
m.LockServerUUID = gocql.UUID{}
default:
m.LockServerUUID = value.(gocql.UUID)
}
case "Name":
switch value.(type) {
case nil:
m.Name = ""
default:
m.Name = value.(string)
}
case "SectionName":
switch value.(type) {
case nil:
m.SectionName = ""
default:
m.SectionName = value.(string)
}
case "PlayerUUID":
switch t := value.(type) {
case nil:
m.PlayerUUID = nil
case gocql.UUID:
m.PlayerUUID = &t
default:
m.PlayerUUID = value.(*gocql.UUID)
}
}
var pair = Field2CQL[key] + "="
switch t := value.(type) {
case nil:
pair += "null"
case bool:
pair += fmt.Sprintf("%v", t)
case int:
pair += fmt.Sprintf("%v", t)
case string:
pair += "'" + t + "'"
case float64:
pair += fmt.Sprintf("%v", t)
case int64:
pair += fmt.Sprintf("%v", t)
case *gocql.UUID:
pair += t.String()
case []*gocql.UUID:
a := []string{}
for _, uuid := range t {
a = append(a, uuid.String())
}
pair += "[" + strings.Join(a, ",") + "]"
case []gocql.UUID:
a := []string{}
for _, uuid := range t {
a = append(a, uuid.String())
}
pair += "[" + strings.Join(a, ",") + "]"
case []string:
a := []string{}
for _, s := range t {
a = append(a, `'`+s+`'`)
}
pair += "[" + strings.Join(a, ",") + "]"
case []int:
a := []string{}
for _, i := range t {
a = append(a, strconv.Itoa(i))
}
pair += "[" + strings.Join(a, ",") + "]"
case gocql.UUID:
pair += t.String()
default:
logger.Error(errors.New(fmt.Sprintf("unknown type: %+v", t)))
}
pairs = append(pairs, pair)
}
q := "update users set " + strings.Join(pairs, ",") + " where user_uuid = " + m.UUID.String()
logger.String(q)
//.........这里部分代码省略.........
示例15: Execute
//.........这里部分代码省略.........
})
}
if session.IsLock {
b, err := star.Send(session.LockServerUUID, model.Fields{
"command": "get_session_lock_state",
"session_uuid": session.UUID,
})
var commandCheckSessionDetector CommandCheckSessionDetector
if err == nil {
json.Unmarshal(b, &commandCheckSessionDetector)
}
if err != nil || commandCheckSessionDetector.IsLock {
// session.Create(c.connection.GetRemoteAddr(), c.connection.GetUserAgent())
session, err = model2_auth_session.Create()
session.Update(model2.Fields{
"RemoteAddr": c.connection.GetRemoteAddr(),
"UserAgent": c.connection.GetUserAgent(),
})
}
logger.String(string(b))
}
// session.Lock()
c.connection.SetSession(session)
sendCommandAuth := SendCommandAuth{
Command: "auth",
SessionUUID: session.UUID.String(),
AuthMethods: c.ctx.Config.Auth.Methods,
IsAuth: session.IsAuth,
PlayerExists: false,
}
if session.IsAuth {
/*
user := model2_user.New()
user.UUID = session.UserUUID
user.Load()
*/
user, _ := model2_user.Load(session.UserUUID)
logger.String(fmt.Sprintf("user: %+v", user))
// check for user lock
if user.IsLock {
b, err := star.Send(user.LockServerUUID, model.Fields{
"command": "get_user_lock_state",
"user_uuid": user.UUID.String(),
})
if err != nil {
} else {
type CommandCheckUserDetector struct {
IsLock bool `json:"is_lock"`
}
var commandCheckUserDetector CommandCheckUserDetector
json.Unmarshal(b, &commandCheckUserDetector)
if commandCheckUserDetector.IsLock {
_, _ = star.Send(user.LockServerUUID, model.Fields{
"command": "star_user_logout",
"user_uuid": user.UUID,
"session_uuid": session.UUID.String(),
})
user.Load()
}
}
}
// user.Lock()
if user.PlayerUUID != nil {
sendCommandAuth.PlayerExists = true
}
sendCommandAuth.User = SendCommandAuthUser{
Name: user.Name,
SectionName: user.SectionName,
}
}
b, err := json.Marshal(sendCommandAuth)
if err != nil {
logger.Error(errors.New(err))
return
}
c.connection.Send(string(b))
}