mirror of
https://github.com/astaxie/beego.git
synced 2025-06-12 12:40:38 +00:00
add golint check and fix all golints
This commit is contained in:
@ -11,11 +11,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CacheSize int = 64
|
||||
// CacheSize set the flush size
|
||||
CacheSize int = 64
|
||||
// Delimiter define the topic delimiter
|
||||
Delimiter string = "##"
|
||||
)
|
||||
|
||||
type AliLSConfig struct {
|
||||
// Config is the Config for Ali Log
|
||||
type Config struct {
|
||||
Project string `json:"project"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
KeyID string `json:"key_id"`
|
||||
@ -35,18 +38,17 @@ type aliLSWriter struct {
|
||||
withMap bool
|
||||
groupMap map[string]*LogGroup
|
||||
lock *sync.Mutex
|
||||
AliLSConfig
|
||||
Config
|
||||
}
|
||||
|
||||
// 创建提供Logger接口的日志服务
|
||||
// NewAliLS create a new Logger
|
||||
func NewAliLS() logs.Logger {
|
||||
alils := new(aliLSWriter)
|
||||
alils.Level = logs.LevelTrace
|
||||
return alils
|
||||
}
|
||||
|
||||
// 读取配置
|
||||
// 初始化必要的数据结构
|
||||
// Init parse config and init struct
|
||||
func (c *aliLSWriter) Init(jsonConfig string) (err error) {
|
||||
|
||||
json.Unmarshal([]byte(jsonConfig), c)
|
||||
@ -55,28 +57,26 @@ func (c *aliLSWriter) Init(jsonConfig string) (err error) {
|
||||
c.FlushWhen = CacheSize
|
||||
}
|
||||
|
||||
// 初始化Project
|
||||
prj := &LogProject{
|
||||
Name: c.Project,
|
||||
Endpoint: c.Endpoint,
|
||||
AccessKeyId: c.KeyID,
|
||||
AccessKeyID: c.KeyID,
|
||||
AccessKeySecret: c.KeySecret,
|
||||
}
|
||||
|
||||
// 获取logstore
|
||||
c.store, err = prj.GetLogStore(c.LogStore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 创建默认Log Group
|
||||
// Create default Log Group
|
||||
c.group = append(c.group, &LogGroup{
|
||||
Topic: proto.String(""),
|
||||
Source: proto.String(c.Source),
|
||||
Logs: make([]*Log, 0, c.FlushWhen),
|
||||
})
|
||||
|
||||
// 创建其它Log Group
|
||||
// Create other Log Group
|
||||
c.groupMap = make(map[string]*LogGroup)
|
||||
for _, topic := range c.Topics {
|
||||
|
||||
@ -114,7 +114,7 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error
|
||||
var lg *LogGroup
|
||||
if c.withMap {
|
||||
|
||||
// 解析出Topic,并匹配LogGroup
|
||||
// Topic,LogGroup
|
||||
strs := strings.SplitN(msg, Delimiter, 2)
|
||||
if len(strs) == 2 {
|
||||
pos := strings.LastIndex(strs[0], " ")
|
||||
@ -123,7 +123,7 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error
|
||||
lg = c.groupMap[topic]
|
||||
}
|
||||
|
||||
// 默认发到空Topic
|
||||
// send to empty Topic
|
||||
if lg == nil {
|
||||
content = msg
|
||||
lg = c.group[0]
|
||||
@ -133,15 +133,14 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error
|
||||
lg = c.group[0]
|
||||
}
|
||||
|
||||
// 生成日志
|
||||
c1 := &Log_Content{
|
||||
c1 := &LogContent{
|
||||
Key: proto.String("msg"),
|
||||
Value: proto.String(content),
|
||||
}
|
||||
|
||||
l := &Log{
|
||||
Time: proto.Uint32(uint32(when.Unix())), // 填写日志时间
|
||||
Contents: []*Log_Content{
|
||||
Time: proto.Uint32(uint32(when.Unix())),
|
||||
Contents: []*LogContent{
|
||||
c1,
|
||||
},
|
||||
}
|
||||
@ -150,7 +149,6 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error
|
||||
lg.Logs = append(lg.Logs, l)
|
||||
c.lock.Unlock()
|
||||
|
||||
// 满足条件则Flush
|
||||
if len(lg.Logs) >= c.FlushWhen {
|
||||
c.flush(lg)
|
||||
}
|
||||
@ -161,7 +159,7 @@ func (c *aliLSWriter) WriteMsg(when time.Time, msg string, level int) (err error
|
||||
// Flush implementing method. empty.
|
||||
func (c *aliLSWriter) Flush() {
|
||||
|
||||
// flush所有group
|
||||
// flush all group
|
||||
for _, lg := range c.group {
|
||||
c.flush(lg)
|
||||
}
|
||||
@ -175,9 +173,6 @@ func (c *aliLSWriter) flush(lg *LogGroup) {
|
||||
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
// 把以上的LogGroup推送到SLS服务器,
|
||||
// SLS服务器会根据该logstore的shard个数自动进行负载均衡。
|
||||
err := c.store.PutLogs(lg)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -1,30 +1,43 @@
|
||||
package alils
|
||||
|
||||
import "github.com/gogo/protobuf/proto"
|
||||
import "fmt"
|
||||
import "math"
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
// discarding unused import gogoproto "."
|
||||
|
||||
import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
|
||||
|
||||
import "io"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
var (
|
||||
// ErrInvalidLengthLog invalid proto
|
||||
ErrInvalidLengthLog = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
// ErrIntOverflowLog overflow
|
||||
ErrIntOverflowLog = fmt.Errorf("proto: integer overflow")
|
||||
)
|
||||
|
||||
// Log define the proto Log
|
||||
type Log struct {
|
||||
Time *uint32 `protobuf:"varint,1,req,name=Time" json:"Time,omitempty"`
|
||||
Contents []*Log_Content `protobuf:"bytes,2,rep,name=Contents" json:"Contents,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
Time *uint32 `protobuf:"varint,1,req,name=Time" json:"Time,omitempty"`
|
||||
Contents []*LogContent `protobuf:"bytes,2,rep,name=Contents" json:"Contents,omitempty"`
|
||||
XXXUnrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Log) Reset() { *m = Log{} }
|
||||
func (m *Log) String() string { return proto.CompactTextString(m) }
|
||||
func (*Log) ProtoMessage() {}
|
||||
// Reset the Log
|
||||
func (m *Log) Reset() { *m = Log{} }
|
||||
|
||||
// String return the Compact Log
|
||||
func (m *Log) String() string { return proto.CompactTextString(m) }
|
||||
|
||||
// ProtoMessage not implemented
|
||||
func (*Log) ProtoMessage() {}
|
||||
|
||||
// GetTime return the Log's Time
|
||||
func (m *Log) GetTime() uint32 {
|
||||
if m != nil && m.Time != nil {
|
||||
return *m.Time
|
||||
@ -32,49 +45,65 @@ func (m *Log) GetTime() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Log) GetContents() []*Log_Content {
|
||||
// GetContents return the Log's Contents
|
||||
func (m *Log) GetContents() []*LogContent {
|
||||
if m != nil {
|
||||
return m.Contents
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Log_Content struct {
|
||||
Key *string `protobuf:"bytes,1,req,name=Key" json:"Key,omitempty"`
|
||||
Value *string `protobuf:"bytes,2,req,name=Value" json:"Value,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
// LogContent define the Log content struct
|
||||
type LogContent struct {
|
||||
Key *string `protobuf:"bytes,1,req,name=Key" json:"Key,omitempty"`
|
||||
Value *string `protobuf:"bytes,2,req,name=Value" json:"Value,omitempty"`
|
||||
XXXUnrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Log_Content) Reset() { *m = Log_Content{} }
|
||||
func (m *Log_Content) String() string { return proto.CompactTextString(m) }
|
||||
func (*Log_Content) ProtoMessage() {}
|
||||
// Reset LogContent
|
||||
func (m *LogContent) Reset() { *m = LogContent{} }
|
||||
|
||||
func (m *Log_Content) GetKey() string {
|
||||
// String return the compact text
|
||||
func (m *LogContent) String() string { return proto.CompactTextString(m) }
|
||||
|
||||
// ProtoMessage not implemented
|
||||
func (*LogContent) ProtoMessage() {}
|
||||
|
||||
// GetKey return the Key
|
||||
func (m *LogContent) GetKey() string {
|
||||
if m != nil && m.Key != nil {
|
||||
return *m.Key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Log_Content) GetValue() string {
|
||||
// GetValue return the Value
|
||||
func (m *LogContent) GetValue() string {
|
||||
if m != nil && m.Value != nil {
|
||||
return *m.Value
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// LogGroup define the logs struct
|
||||
type LogGroup struct {
|
||||
Logs []*Log `protobuf:"bytes,1,rep,name=Logs" json:"Logs,omitempty"`
|
||||
Reserved *string `protobuf:"bytes,2,opt,name=Reserved" json:"Reserved,omitempty"`
|
||||
Topic *string `protobuf:"bytes,3,opt,name=Topic" json:"Topic,omitempty"`
|
||||
Source *string `protobuf:"bytes,4,opt,name=Source" json:"Source,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
Logs []*Log `protobuf:"bytes,1,rep,name=Logs" json:"Logs,omitempty"`
|
||||
Reserved *string `protobuf:"bytes,2,opt,name=Reserved" json:"Reserved,omitempty"`
|
||||
Topic *string `protobuf:"bytes,3,opt,name=Topic" json:"Topic,omitempty"`
|
||||
Source *string `protobuf:"bytes,4,opt,name=Source" json:"Source,omitempty"`
|
||||
XXXUnrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *LogGroup) Reset() { *m = LogGroup{} }
|
||||
func (m *LogGroup) String() string { return proto.CompactTextString(m) }
|
||||
func (*LogGroup) ProtoMessage() {}
|
||||
// Reset LogGroup
|
||||
func (m *LogGroup) Reset() { *m = LogGroup{} }
|
||||
|
||||
// String return the compact text
|
||||
func (m *LogGroup) String() string { return proto.CompactTextString(m) }
|
||||
|
||||
// ProtoMessage not implemented
|
||||
func (*LogGroup) ProtoMessage() {}
|
||||
|
||||
// GetLogs return the loggroup logs
|
||||
func (m *LogGroup) GetLogs() []*Log {
|
||||
if m != nil {
|
||||
return m.Logs
|
||||
@ -82,6 +111,7 @@ func (m *LogGroup) GetLogs() []*Log {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetReserved return Reserved
|
||||
func (m *LogGroup) GetReserved() string {
|
||||
if m != nil && m.Reserved != nil {
|
||||
return *m.Reserved
|
||||
@ -89,6 +119,7 @@ func (m *LogGroup) GetReserved() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetTopic return Topic
|
||||
func (m *LogGroup) GetTopic() string {
|
||||
if m != nil && m.Topic != nil {
|
||||
return *m.Topic
|
||||
@ -96,6 +127,7 @@ func (m *LogGroup) GetTopic() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetSource return Source
|
||||
func (m *LogGroup) GetSource() string {
|
||||
if m != nil && m.Source != nil {
|
||||
return *m.Source
|
||||
@ -103,15 +135,22 @@ func (m *LogGroup) GetSource() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// LogGroupList define the LogGroups
|
||||
type LogGroupList struct {
|
||||
LogGroups []*LogGroup `protobuf:"bytes,1,rep,name=logGroups" json:"logGroups,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
LogGroups []*LogGroup `protobuf:"bytes,1,rep,name=logGroups" json:"logGroups,omitempty"`
|
||||
XXXUnrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *LogGroupList) Reset() { *m = LogGroupList{} }
|
||||
func (m *LogGroupList) String() string { return proto.CompactTextString(m) }
|
||||
func (*LogGroupList) ProtoMessage() {}
|
||||
// Reset LogGroupList
|
||||
func (m *LogGroupList) Reset() { *m = LogGroupList{} }
|
||||
|
||||
// String return compact text
|
||||
func (m *LogGroupList) String() string { return proto.CompactTextString(m) }
|
||||
|
||||
// ProtoMessage not implemented
|
||||
func (*LogGroupList) ProtoMessage() {}
|
||||
|
||||
// GetLogGroups return the LogGroups
|
||||
func (m *LogGroupList) GetLogGroups() []*LogGroup {
|
||||
if m != nil {
|
||||
return m.LogGroups
|
||||
@ -119,6 +158,7 @@ func (m *LogGroupList) GetLogGroups() []*LogGroup {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal the logs to byte slice
|
||||
func (m *Log) Marshal() (data []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
@ -129,6 +169,7 @@ func (m *Log) Marshal() (data []byte, err error) {
|
||||
return data[:n], nil
|
||||
}
|
||||
|
||||
// MarshalTo data
|
||||
func (m *Log) MarshalTo(data []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
@ -136,11 +177,10 @@ func (m *Log) MarshalTo(data []byte) (int, error) {
|
||||
_ = l
|
||||
if m.Time == nil {
|
||||
return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("Time")
|
||||
} else {
|
||||
data[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintLog(data, i, uint64(*m.Time))
|
||||
}
|
||||
data[i] = 0x8
|
||||
i++
|
||||
i = encodeVarintLog(data, i, uint64(*m.Time))
|
||||
if len(m.Contents) > 0 {
|
||||
for _, msg := range m.Contents {
|
||||
data[i] = 0x12
|
||||
@ -153,13 +193,14 @@ func (m *Log) MarshalTo(data []byte) (int, error) {
|
||||
i += n
|
||||
}
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
i += copy(data[i:], m.XXXUnrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *Log_Content) Marshal() (data []byte, err error) {
|
||||
// Marshal LogContent
|
||||
func (m *LogContent) Marshal() (data []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
n, err := m.MarshalTo(data)
|
||||
@ -169,33 +210,34 @@ func (m *Log_Content) Marshal() (data []byte, err error) {
|
||||
return data[:n], nil
|
||||
}
|
||||
|
||||
func (m *Log_Content) MarshalTo(data []byte) (int, error) {
|
||||
// MarshalTo logcontent to data
|
||||
func (m *LogContent) MarshalTo(data []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.Key == nil {
|
||||
return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("Key")
|
||||
} else {
|
||||
data[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintLog(data, i, uint64(len(*m.Key)))
|
||||
i += copy(data[i:], *m.Key)
|
||||
}
|
||||
data[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintLog(data, i, uint64(len(*m.Key)))
|
||||
i += copy(data[i:], *m.Key)
|
||||
|
||||
if m.Value == nil {
|
||||
return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("Value")
|
||||
} else {
|
||||
data[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintLog(data, i, uint64(len(*m.Value)))
|
||||
i += copy(data[i:], *m.Value)
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
data[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintLog(data, i, uint64(len(*m.Value)))
|
||||
i += copy(data[i:], *m.Value)
|
||||
if m.XXXUnrecognized != nil {
|
||||
i += copy(data[i:], m.XXXUnrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// Marshal LogGroup
|
||||
func (m *LogGroup) Marshal() (data []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
@ -206,6 +248,7 @@ func (m *LogGroup) Marshal() (data []byte, err error) {
|
||||
return data[:n], nil
|
||||
}
|
||||
|
||||
// MarshalTo LogGroup to data
|
||||
func (m *LogGroup) MarshalTo(data []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
@ -241,12 +284,13 @@ func (m *LogGroup) MarshalTo(data []byte) (int, error) {
|
||||
i = encodeVarintLog(data, i, uint64(len(*m.Source)))
|
||||
i += copy(data[i:], *m.Source)
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
i += copy(data[i:], m.XXXUnrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// Marshal LogGroupList
|
||||
func (m *LogGroupList) Marshal() (data []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
@ -257,6 +301,7 @@ func (m *LogGroupList) Marshal() (data []byte, err error) {
|
||||
return data[:n], nil
|
||||
}
|
||||
|
||||
// MarshalTo LogGroupList to data
|
||||
func (m *LogGroupList) MarshalTo(data []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
@ -274,8 +319,8 @@ func (m *LogGroupList) MarshalTo(data []byte) (int, error) {
|
||||
i += n
|
||||
}
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
i += copy(data[i:], m.XXXUnrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
@ -307,6 +352,8 @@ func encodeVarintLog(data []byte, offset int, v uint64) int {
|
||||
data[offset] = uint8(v)
|
||||
return offset + 1
|
||||
}
|
||||
|
||||
// Size return the log's size
|
||||
func (m *Log) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
@ -319,13 +366,14 @@ func (m *Log) Size() (n int) {
|
||||
n += 1 + l + sovLog(uint64(l))
|
||||
}
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
n += len(m.XXXUnrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *Log_Content) Size() (n int) {
|
||||
// Size return LogContent size based on Key and Value
|
||||
func (m *LogContent) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
if m.Key != nil {
|
||||
@ -336,12 +384,13 @@ func (m *Log_Content) Size() (n int) {
|
||||
l = len(*m.Value)
|
||||
n += 1 + l + sovLog(uint64(l))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
n += len(m.XXXUnrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Size return LogGroup size based on Logs
|
||||
func (m *LogGroup) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
@ -363,12 +412,13 @@ func (m *LogGroup) Size() (n int) {
|
||||
l = len(*m.Source)
|
||||
n += 1 + l + sovLog(uint64(l))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
n += len(m.XXXUnrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Size return LogGroupList size
|
||||
func (m *LogGroupList) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
@ -378,8 +428,8 @@ func (m *LogGroupList) Size() (n int) {
|
||||
n += 1 + l + sovLog(uint64(l))
|
||||
}
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
if m.XXXUnrecognized != nil {
|
||||
n += len(m.XXXUnrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
@ -397,6 +447,8 @@ func sovLog(x uint64) (n int) {
|
||||
func sozLog(x uint64) (n int) {
|
||||
return sovLog((x << 1) ^ (x >> 63))
|
||||
}
|
||||
|
||||
// Unmarshal data to log
|
||||
func (m *Log) Unmarshal(data []byte) error {
|
||||
var hasFields [1]uint64
|
||||
l := len(data)
|
||||
@ -474,7 +526,7 @@ func (m *Log) Unmarshal(data []byte) error {
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Contents = append(m.Contents, &Log_Content{})
|
||||
m.Contents = append(m.Contents, &LogContent{})
|
||||
if err := m.Contents[len(m.Contents)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -491,7 +543,7 @@ func (m *Log) Unmarshal(data []byte) error {
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
m.XXXUnrecognized = append(m.XXXUnrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
@ -504,7 +556,9 @@ func (m *Log) Unmarshal(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *Log_Content) Unmarshal(data []byte) error {
|
||||
|
||||
// Unmarshal data to LogContent
|
||||
func (m *LogContent) Unmarshal(data []byte) error {
|
||||
var hasFields [1]uint64
|
||||
l := len(data)
|
||||
iNdEx := 0
|
||||
@ -608,7 +662,7 @@ func (m *Log_Content) Unmarshal(data []byte) error {
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
m.XXXUnrecognized = append(m.XXXUnrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
@ -624,6 +678,8 @@ func (m *Log_Content) Unmarshal(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmarshal data to LogGroup
|
||||
func (m *LogGroup) Unmarshal(data []byte) error {
|
||||
l := len(data)
|
||||
iNdEx := 0
|
||||
@ -786,7 +842,7 @@ func (m *LogGroup) Unmarshal(data []byte) error {
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
m.XXXUnrecognized = append(m.XXXUnrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
@ -796,6 +852,8 @@ func (m *LogGroup) Unmarshal(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmarshal data to LogGroupList
|
||||
func (m *LogGroupList) Unmarshal(data []byte) error {
|
||||
l := len(data)
|
||||
iNdEx := 0
|
||||
@ -868,7 +926,7 @@ func (m *LogGroupList) Unmarshal(data []byte) error {
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
m.XXXUnrecognized = append(m.XXXUnrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
@ -878,6 +936,7 @@ func (m *LogGroupList) Unmarshal(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func skipLog(data []byte) (n int, err error) {
|
||||
l := len(data)
|
||||
iNdEx := 0
|
||||
@ -940,7 +999,7 @@ func skipLog(data []byte) (n int, err error) {
|
||||
case 3:
|
||||
for {
|
||||
var innerWire uint64
|
||||
var start int = iNdEx
|
||||
var start = iNdEx
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowLog
|
||||
@ -977,8 +1036,3 @@ func skipLog(data []byte) (n int, err error) {
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthLog = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowLog = fmt.Errorf("proto: integer overflow")
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package alils
|
||||
|
||||
// InputDetail define log detail
|
||||
type InputDetail struct {
|
||||
LogType string `json:"logType"`
|
||||
LogPath string `json:"logPath"`
|
||||
@ -14,11 +15,13 @@ type InputDetail struct {
|
||||
TopicFormat string `json:"topicFormat"`
|
||||
}
|
||||
|
||||
// OutputDetail define the output detail
|
||||
type OutputDetail struct {
|
||||
Endpoint string `json:"endpoint"`
|
||||
LogStoreName string `json:"logstoreName"`
|
||||
}
|
||||
|
||||
// LogConfig define Log Config
|
||||
type LogConfig struct {
|
||||
Name string `json:"configName"`
|
||||
InputType string `json:"inputType"`
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Package sls implements the SDK(v0.5.0) of Simple Log Service(abbr. SLS).
|
||||
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr. SLS).
|
||||
|
||||
For more description about SLS, please read this article:
|
||||
http://gitlab.alibaba-inc.com/sls/doc.
|
||||
@ -20,19 +20,20 @@ type errorMessage struct {
|
||||
Message string `json:"errorMessage"`
|
||||
}
|
||||
|
||||
// LogProject Define the Ali Project detail
|
||||
type LogProject struct {
|
||||
Name string // Project name
|
||||
Endpoint string // IP or hostname of SLS endpoint
|
||||
AccessKeyId string
|
||||
AccessKeyID string
|
||||
AccessKeySecret string
|
||||
}
|
||||
|
||||
// NewLogProject creates a new SLS project.
|
||||
func NewLogProject(name, endpoint, accessKeyId, accessKeySecret string) (p *LogProject, err error) {
|
||||
func NewLogProject(name, endpoint, AccessKeyID, accessKeySecret string) (p *LogProject, err error) {
|
||||
p = &LogProject{
|
||||
Name: name,
|
||||
Endpoint: endpoint,
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeyID: AccessKeyID,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
return p, nil
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// LogStore Store the logs
|
||||
type LogStore struct {
|
||||
Name string `json:"logstoreName"`
|
||||
TTL int
|
||||
@ -23,6 +24,7 @@ type LogStore struct {
|
||||
project *LogProject
|
||||
}
|
||||
|
||||
// Shard define the Log Shard
|
||||
type Shard struct {
|
||||
ShardID int `json:"shardID"`
|
||||
}
|
||||
@ -116,16 +118,16 @@ func (s *LogStore) PutLogs(lg *LogGroup) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetCursor gets log cursor of one shard specified by shardId.
|
||||
// GetCursor gets log cursor of one shard specified by shardID.
|
||||
// The from can be in three form: a) unix timestamp in seccond, b) "begin", c) "end".
|
||||
// For more detail please read: http://gitlab.alibaba-inc.com/sls/doc/blob/master/api/shard.md#logstore
|
||||
func (s *LogStore) GetCursor(shardId int, from string) (cursor string, err error) {
|
||||
func (s *LogStore) GetCursor(shardID int, from string) (cursor string, err error) {
|
||||
h := map[string]string{
|
||||
"x-sls-bodyrawsize": "0",
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("/logstores/%v/shards/%v?type=cursor&from=%v",
|
||||
s.Name, shardId, from)
|
||||
s.Name, shardID, from)
|
||||
|
||||
r, err := request(s.project, "GET", uri, h, nil)
|
||||
if err != nil {
|
||||
@ -163,10 +165,10 @@ func (s *LogStore) GetCursor(shardId int, from string) (cursor string, err error
|
||||
return
|
||||
}
|
||||
|
||||
// GetLogsBytes gets logs binary data from shard specified by shardId according cursor.
|
||||
// GetLogsBytes gets logs binary data from shard specified by shardID according cursor.
|
||||
// The logGroupMaxCount is the max number of logGroup could be returned.
|
||||
// The nextCursor is the next curosr can be used to read logs at next time.
|
||||
func (s *LogStore) GetLogsBytes(shardId int, cursor string,
|
||||
func (s *LogStore) GetLogsBytes(shardID int, cursor string,
|
||||
logGroupMaxCount int) (out []byte, nextCursor string, err error) {
|
||||
|
||||
h := map[string]string{
|
||||
@ -176,7 +178,7 @@ func (s *LogStore) GetLogsBytes(shardId int, cursor string,
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("/logstores/%v/shards/%v?type=logs&cursor=%v&count=%v",
|
||||
s.Name, shardId, cursor, logGroupMaxCount)
|
||||
s.Name, shardID, cursor, logGroupMaxCount)
|
||||
|
||||
r, err := request(s.project, "GET", uri, h, nil)
|
||||
if err != nil {
|
||||
@ -249,13 +251,13 @@ func LogsBytesDecode(data []byte) (gl *LogGroupList, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetLogs gets logs from shard specified by shardId according cursor.
|
||||
// GetLogs gets logs from shard specified by shardID according cursor.
|
||||
// The logGroupMaxCount is the max number of logGroup could be returned.
|
||||
// The nextCursor is the next curosr can be used to read logs at next time.
|
||||
func (s *LogStore) GetLogs(shardId int, cursor string,
|
||||
func (s *LogStore) GetLogs(shardID int, cursor string,
|
||||
logGroupMaxCount int) (gl *LogGroupList, nextCursor string, err error) {
|
||||
|
||||
out, nextCursor, err := s.GetLogsBytes(shardId, cursor, logGroupMaxCount)
|
||||
out, nextCursor, err := s.GetLogsBytes(shardID, cursor, logGroupMaxCount)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -8,18 +8,20 @@ import (
|
||||
"net/http/httputil"
|
||||
)
|
||||
|
||||
type MachinGroupAttribute struct {
|
||||
// MachineGroupAttribute define the Attribute
|
||||
type MachineGroupAttribute struct {
|
||||
ExternalName string `json:"externalName"`
|
||||
TopicName string `json:"groupTopic"`
|
||||
}
|
||||
|
||||
// MachineGroup define the machine Group
|
||||
type MachineGroup struct {
|
||||
Name string `json:"groupName"`
|
||||
Type string `json:"groupType"`
|
||||
MachineIdType string `json:"machineIdentifyType"`
|
||||
MachineIdList []string `json:"machineList"`
|
||||
MachineIDType string `json:"machineIdentifyType"`
|
||||
MachineIDList []string `json:"machineList"`
|
||||
|
||||
Attribute MachinGroupAttribute `json:"groupAttribute"`
|
||||
Attribute MachineGroupAttribute `json:"groupAttribute"`
|
||||
|
||||
CreateTime uint32
|
||||
LastModifyTime uint32
|
||||
@ -27,12 +29,14 @@ type MachineGroup struct {
|
||||
project *LogProject
|
||||
}
|
||||
|
||||
// Machine define the Machine
|
||||
type Machine struct {
|
||||
IP string
|
||||
UniqueId string `json:"machine-uniqueid"`
|
||||
UserdefinedId string `json:"userdefined-id"`
|
||||
UniqueID string `json:"machine-uniqueid"`
|
||||
UserdefinedID string `json:"userdefined-id"`
|
||||
}
|
||||
|
||||
// MachineList define the Machine List
|
||||
type MachineList struct {
|
||||
Total int
|
||||
Machines []*Machine
|
||||
|
@ -33,12 +33,12 @@ func request(project *LogProject, method, uri string, headers map[string]string,
|
||||
}
|
||||
|
||||
// Calc Authorization
|
||||
// Authorization = "SLS <AccessKeyId>:<Signature>"
|
||||
// Authorization = "SLS <AccessKeyID>:<Signature>"
|
||||
digest, err := signature(project, method, uri, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
auth := fmt.Sprintf("SLS %v:%v", project.AccessKeyId, digest)
|
||||
auth := fmt.Sprintf("SLS %v:%v", project.AccessKeyID, digest)
|
||||
headers["Authorization"] = auth
|
||||
|
||||
// Initialize http request
|
||||
|
@ -170,7 +170,7 @@ func (w *fileLogWriter) initFd() error {
|
||||
fd := w.fileWriter
|
||||
fInfo, err := fd.Stat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("get stat err: %s\n", err)
|
||||
return fmt.Errorf("get stat err: %s", err)
|
||||
}
|
||||
w.maxSizeCurSize = int(fInfo.Size())
|
||||
w.dailyOpenTime = time.Now()
|
||||
|
@ -492,9 +492,9 @@ func (bl *BeeLogger) flush() {
|
||||
}
|
||||
|
||||
// beeLogger references the used application logger.
|
||||
var beeLogger *BeeLogger = NewLogger()
|
||||
var beeLogger = NewLogger()
|
||||
|
||||
// GetLogger returns the default BeeLogger
|
||||
// GetBeeLogger returns the default BeeLogger
|
||||
func GetBeeLogger() *BeeLogger {
|
||||
return beeLogger
|
||||
}
|
||||
@ -534,6 +534,7 @@ func Reset() {
|
||||
beeLogger.Reset()
|
||||
}
|
||||
|
||||
// Async set the beelogger with Async mode and hold msglen messages
|
||||
func Async(msgLen ...int64) *BeeLogger {
|
||||
return beeLogger.Async(msgLen...)
|
||||
}
|
||||
|
@ -139,6 +139,11 @@ var (
|
||||
reset = string([]byte{27, 91, 48, 109})
|
||||
)
|
||||
|
||||
// ColorByStatus return color by http code
|
||||
// 2xx return Green
|
||||
// 3xx return White
|
||||
// 4xx return Yellow
|
||||
// 5xx return Red
|
||||
func ColorByStatus(cond bool, code int) string {
|
||||
switch {
|
||||
case code >= 200 && code < 300:
|
||||
@ -152,6 +157,14 @@ func ColorByStatus(cond bool, code int) string {
|
||||
}
|
||||
}
|
||||
|
||||
// ColorByMethod return color by http code
|
||||
// GET return Blue
|
||||
// POST return Cyan
|
||||
// PUT return Yellow
|
||||
// DELETE return Red
|
||||
// PATCH return Green
|
||||
// HEAD return Magenta
|
||||
// OPTIONS return WHITE
|
||||
func ColorByMethod(cond bool, method string) string {
|
||||
switch method {
|
||||
case "GET":
|
||||
@ -173,10 +186,10 @@ func ColorByMethod(cond bool, method string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Guard Mutex to guarantee atomicity of W32Debug(string) function
|
||||
// Guard Mutex to guarantee atomic of W32Debug(string) function
|
||||
var mu sync.Mutex
|
||||
|
||||
// Helper method to output colored logs in Windows terminals
|
||||
// W32Debug Helper method to output colored logs in Windows terminals
|
||||
func W32Debug(msg string) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
Reference in New Issue
Block a user