当前位置: 首页>>代码示例>>Golang>>正文


Golang nsq-logger.Error函数代码示例

本文整理汇总了Golang中github.com/gonet2/libs/nsq-logger.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: load_names

// get stored service name
func (p *service_pool) load_names() {
	p.service_names = make(map[string]bool)
	client := p.client_pool.Get().(*etcd.Client)
	defer func() {
		p.client_pool.Put(client)
	}()

	// get the keys under directory
	log.Info("reading names:", DEFAULT_NAME_FILE)
	resp, err := client.Get(DEFAULT_NAME_FILE, false, false)
	if err != nil {
		log.Error(err)
		return
	}

	// validation check
	if resp.Node.Dir {
		log.Error("names is not a file")
		return
	}

	// split names
	names := strings.Split(resp.Node.Value, "\n")
	log.Info("all service names:", names)
	for _, v := range names {
		p.service_names[DEFAULT_SERVICE_PATH+"/"+strings.TrimSpace(v)] = true
	}

	p.enable_name_check = true
}
开发者ID:tonycoming,项目名称:libs,代码行数:31,代码来源:services.go

示例2: LoadFile

//---------------------------------------------------------- 读取GridFS文件
func LoadFile(filename string) (ok bool, content []byte) {
	ms := _global_ms.Copy()
	defer ms.Close()

	buf := &bytes.Buffer{}
	file, err := ms.DB("").GridFS("fs").Open(filename)
	if err != nil {
		log.Warning("gridfs", filename, err)
		return false, nil
	}

	n, err := io.Copy(buf, file)
	if err != nil {
		log.Error("gridfs", filename, n, err)
		return false, nil
	}

	err = file.Close()
	if err != nil {
		log.Error("gridfs", filename, err)
		return false, nil
	}

	log.Trace("gridfs", filename, "load from GridFS!!")
	return true, buf.Bytes()
}
开发者ID:tonycoming,项目名称:libs,代码行数:27,代码来源:mongo.go

示例3: connect_all

// connect to all services
func (p *service_pool) connect_all(directory string) {
	client := p.client_pool.Get().(*etcd.Client)
	defer func() {
		p.client_pool.Put(client)
	}()

	// get the keys under directory
	log.Info("connecting services under:", directory)
	resp, err := client.Get(directory, true, true)
	if err != nil {
		log.Error(err)
		return
	}

	// validation check
	if !resp.Node.Dir {
		log.Error("not a directory")
		return
	}

	for _, node := range resp.Node.Nodes {
		if node.Dir { // service directory
			for _, service := range node.Nodes {
				p.add_service(service.Key, service.Value)
			}
		} else {
			log.Warning("malformed service directory:", node.Key)
		}
	}
	log.Info("services add complete")
}
开发者ID:anders007,项目名称:libs,代码行数:32,代码来源:services.go

示例4: GetUUID

// generate an unique uuid
func (s *server) GetUUID(context.Context, *pb.Snowflake_NullRequest) (*pb.Snowflake_UUID, error) {
	s.Lock()
	defer s.Unlock()

	// get a correct serial number
	t := s.ts()
	if t < s.last_ts { // clock shift backward
		log.Error("clock shift happened, waiting until the clock moving to the next millisecond.")
		t = s.wait_ms(s.last_ts)
	}

	if s.last_ts == t { // same millisecond
		s.sn = (s.sn + 1) & SN_MASK
		if s.sn == 0 { // serial number overflows, wait until next ms
			t = s.wait_ms(s.last_ts)
		}
	} else { // new millsecond, reset serial number to 0
		s.sn = 0
	}
	// remember last timestamp
	s.last_ts = t

	// generate uuid, format:
	//
	// 0		0.................0		0..............0	0........0
	// 1-bit	41bit timestamp			10bit machine-id	12bit sn
	var uuid uint64
	uuid |= (uint64(t) & TS_MASK) << 22
	uuid |= s.machine_id
	uuid |= s.sn

	return &pb.Snowflake_UUID{uuid}, nil
}
开发者ID:anders007,项目名称:snowflake,代码行数:34,代码来源:service.go

示例5: init

func (ps *PubSub) init() {
	ps.ch_msg = make(chan interface{})
	call := func(rf reflect.Value, in []reflect.Value) {
		defer func() { // do not let callback panic the pubsub
			if err := recover(); err != nil {
				log.Error(err)
			}
		}()
		rf.Call(in)
	}

	go func() {
		for v := range ps.ch_msg {
			rv := reflect.ValueOf(v)
			ps.Lock()
			for _, sub := range ps.subs {
				rf := reflect.ValueOf(sub.f)
				if rv.Type() == reflect.ValueOf(sub.f).Type().In(0) { // parameter type match
					call(rf, []reflect.Value{rv})
				}
			}
			ps.Unlock()
		}
	}()
}
开发者ID:dexter-cn,项目名称:chat,代码行数:25,代码来源:pubsub.go

示例6: uuid_task

// uuid generator
func (s *server) uuid_task() {
	var sn uint64     // 12-bit serial no
	var last_ts int64 // last timestamp
	for {
		ret := <-s.ch_proc
		// get a correct serial number
		t := ts()
		if t < last_ts { // clock shift backward
			log.Error("clock shift happened, waiting until the clock moving to the next millisecond.")
			t = s.wait_ms(last_ts)
		}

		if last_ts == t { // same millisecond
			sn = (sn + 1) & SN_MASK
			if sn == 0 { // serial number overflows, wait until next ms
				t = s.wait_ms(last_ts)
			}
		} else { // new millsecond, reset serial number to 0
			sn = 0
		}
		// remember last timestamp
		last_ts = t

		// generate uuid, format:
		//
		// 0		0.................0		0..............0	0........0
		// 1-bit	41bit timestamp			10bit machine-id	12bit sn
		var uuid uint64
		uuid |= (uint64(t) & TS_MASK) << 22
		uuid |= s.machine_id
		uuid |= sn
		ret <- uuid
	}
}
开发者ID:en,项目名称:snowflake,代码行数:35,代码来源:service.go

示例7: Next

// get next value of a key, like auto-increment in mysql
func (s *server) Next(ctx context.Context, in *pb.Snowflake_Key) (*pb.Snowflake_Value, error) {
	client := s.client_pool.Get().(*etcd.Client)
	defer func() {
		s.client_pool.Put(client)
	}()
	key := PATH + in.Name

	for i := 0; i < RETRY_MAX; i++ {
		// get the key
		resp, err := client.Get(key, false, false)
		if err != nil {
			log.Critical(err)
			return nil, errors.New("Key not exists, need to create first")
		}

		// get prevValue & prevIndex
		prevValue, err := strconv.Atoi(resp.Node.Value)
		if err != nil {
			log.Critical(err)
			return nil, errors.New("marlformed value")
		}
		prevIndex := resp.Node.ModifiedIndex

		// CAS
		resp, err = client.CompareAndSwap(key, fmt.Sprint(prevValue+1), 0, resp.Node.Value, prevIndex)
		if err != nil {
			log.Error(err)
			<-time.After(RETRY_DELAY)
			continue
		}
		return &pb.Snowflake_Value{int64(prevValue + 1)}, nil
	}
	return nil, errors.New("etcd server busy")
}
开发者ID:anders007,项目名称:snowflake,代码行数:35,代码来源:service.go

示例8: archive_task

func (arch *Archiver) archive_task() {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM)
	timer := time.After(REDO_ROTATE_INTERVAL)
	db := arch.new_redolog()
	for {
		select {
		case msg := <-arch.pending:
			var record map[string]interface{}
			err := msgpack.Unmarshal(msg, &record)
			if err != nil {
				log.Error(err)
				continue
			}

			db.Update(func(tx *bolt.Tx) error {
				b := tx.Bucket([]byte(BOLTDB_BUCKET))
				err := b.Put([]byte(fmt.Sprint(record["TS"])), msg)
				return err
			})
		case <-timer:
			db.Close()
			// rotate redolog
			db = arch.new_redolog()
			timer = time.After(REDO_ROTATE_INTERVAL)
		case <-sig:
			db.Close()
			log.Info("SIGTERM")
			os.Exit(0)
		}
	}
}
开发者ID:tonycoming,项目名称:arch,代码行数:32,代码来源:arch.go

示例9: Unlock

// unlock a key on etcd, returns false if the key cannot be successfully unlocked
func (m *Mutex) Unlock() bool {
	client := _client_pool.Get().(*etcd.Client)
	_, err := client.CompareAndDelete(LOCK_PATH+m.key, VALUE, m.prevIndex)
	if err != nil {
		log.Error(SERVICE, err)
		return false
	}
	return true
}
开发者ID:tonycoming,项目名称:libs,代码行数:10,代码来源:mutex.go

示例10: query

func (s *server) query(ip net.IP) *City {
	city := &City{}
	err := s.mmdb.Lookup(ip, city)
	if err != nil {
		log.Error(err)
		return nil
	}

	return city
}
开发者ID:tonycoming,项目名称:geoip,代码行数:10,代码来源:service.go

示例11: P_user_login_req

// 玩家登陆过程
func P_user_login_req(sess *Session, reader *packet.Packet) []byte {
	// TODO: 登陆鉴权
	sess.UserId = 1

	// TODO: 选择登陆服务器
	sess.GSID = DEFAULT_GSID

	// 选服
	cli, err := sp.GetServiceWithId(sp.SERVICE_GAME, sess.GSID)
	if err != nil {
		log.Critical(err)
		return nil
	}

	// type assertion
	game_cli, ok := cli.(spp.GameServiceClient)
	if !ok {
		log.Critical("cannot do type assertion on: %v", sess.GSID)
		return nil
	}

	// 开启到游戏服的流
	// TODO: 处理context,设定超时
	stream, err := game_cli.Stream(context.Background())
	if err != nil {
		log.Critical(err)
		return nil
	}
	sess.Stream = stream

	// 在game注册
	// TODO: 新用户的创建由game处理
	sess.Stream.Send(&spp.Game_Frame{Type: spp.Game_Register, UserId: sess.UserId})

	// 读取GAME返回消息
	fetcher_task := func(sess *Session) {
		for {
			in, err := sess.Stream.Recv()
			if err == io.EOF { // 流关闭
				log.Trace(err)
				return
			}
			if err != nil {
				log.Error(err)
				return
			}
			sess.MQ <- *in
		}
	}
	go fetcher_task(sess)
	return packet.Pack(Code["user_login_ack"], user_snapshot{F_uid: sess.UserId}, nil)
}
开发者ID:anders007,项目名称:agent,代码行数:53,代码来源:handle.go

示例12: timer_work

// 玩家1分钟定时器
func timer_work(sess *Session, out *Buffer) {
	// 发包频率控制,太高的RPS直接踢掉
	interval := time.Now().Sub(sess.ConnectTime).Minutes()
	if interval >= 1 { // 登录时长超过1分钟才开始统计rpm。防脉冲
		rpm := float64(sess.PacketCount) / interval

		if rpm > RPM_LIMIT {
			sess.Flag |= SESS_KICKED_OUT
			log.Error("玩家RPM太高 RPM:", rpm)
			return
		}
	}
}
开发者ID:tarmylan,项目名称:agent,代码行数:14,代码来源:timer_work.go

示例13: P_user_login_req

// 玩家登陆过程
func P_user_login_req(sess *Session, reader *packet.Packet) []byte {
	// TODO: 登陆鉴权
	sess.UserId = 1

	// TODO: 选择登陆服务器
	sess.GSID = DEFAULT_GSID

	// 选服
	conn := sp.GetServiceWithId(sp.DEFAULT_SERVICE_PATH+"/game", sess.GSID)
	if conn == nil {
		log.Critical("cannot get game service:", sess.GSID)
		return nil
	}
	cli := pb.NewGameServiceClient(conn)

	// 开启到游戏服的流
	// TODO: 处理context,设定超时
	stream, err := cli.Stream(context.Background())
	if err != nil {
		log.Critical(err)
		return nil
	}
	sess.Stream = stream

	// 在game注册
	// TODO: 新用户的创建由game处理
	sess.Stream.Send(&pb.Game_Frame{Type: pb.Game_Register, UserId: sess.UserId})

	// 读取GAME返回消息
	fetcher_task := func(sess *Session) {
		for {
			in, err := sess.Stream.Recv()
			if err == io.EOF { // 流关闭
				log.Trace(err)
				return
			}
			if err != nil {
				log.Error(err)
				return
			}
			select {
			case sess.MQ <- *in:
			case <-sess.Die:
			}
		}
	}
	go fetcher_task(sess)
	return packet.Pack(Code["user_login_succeed_ack"], S_user_snapshot{F_uid: sess.UserId}, nil)
}
开发者ID:CowLeo,项目名称:agent,代码行数:50,代码来源:handle.go

示例14: PrintPanicStack

func PrintPanicStack(extras ...interface{}) {
	if x := recover(); x != nil {
		log.Error(x)
		i := 0
		funcName, file, line, ok := runtime.Caller(i)
		for ok {
			log.Errorf("frame %v:[func:%v,file:%v,line:%v]\n", i, runtime.FuncForPC(funcName).Name(), file, line)
			i++
			funcName, file, line, ok = runtime.Caller(i)
		}

		for k := range extras {
			log.Errorf("EXRAS#%v DATA:%v\n", k, spew.Sdump(extras[k]))
		}
	}
}
开发者ID:CowLeo,项目名称:agent,代码行数:16,代码来源:stack.go

示例15: init

func init() {
	addr := DEFAULT_STATSD_HOST
	if env := os.Getenv(ENV_STATSD); env != "" {
		addr = env
	}

	s, err := g2s.Dial("udp", addr)
	if err == nil {
		_statter = s
	} else {
		_statter = g2s.Noop()
		log.Error(err)
	}

	go pprof_task()
}
开发者ID:xinhp,项目名称:libs,代码行数:16,代码来源:pprof.go


注:本文中的github.com/gonet2/libs/nsq-logger.Error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。