id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
4,800
ligato/cn-infra
processmanager/status/status.go
ReadStatusFromFile
func (r *Reader) ReadStatusFromFile(file *os.File) *File { return r.parse(file) }
go
func (r *Reader) ReadStatusFromFile(file *os.File) *File { return r.parse(file) }
[ "func", "(", "r", "*", "Reader", ")", "ReadStatusFromFile", "(", "file", "*", "os", ".", "File", ")", "*", "File", "{", "return", "r", ".", "parse", "(", "file", ")", "\n", "}" ]
// ReadStatusFromFile allows to eventually read status from custom location and parse it directly
[ "ReadStatusFromFile", "allows", "to", "eventually", "read", "status", "from", "custom", "location", "and", "parse", "it", "directly" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/status/status.go#L136-L138
4,801
ligato/cn-infra
processmanager/status/status.go
toInt
func (r *Reader) toInt(input string) int { result, err := strconv.Atoi(prune(input)) if err != nil { return -1 } return result }
go
func (r *Reader) toInt(input string) int { result, err := strconv.Atoi(prune(input)) if err != nil { return -1 } return result }
[ "func", "(", "r", "*", "Reader", ")", "toInt", "(", "input", "string", ")", "int", "{", "result", ",", "err", ":=", "strconv", ".", "Atoi", "(", "prune", "(", "input", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", "\n", "}", "\n", "return", "result", "\n", "}" ]
// This method should save a few lines, converting provided string to int while error is logged but not returned
[ "This", "method", "should", "save", "a", "few", "lines", "converting", "provided", "string", "to", "int", "while", "error", "is", "logged", "but", "not", "returned" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/status/status.go#L282-L288
4,802
ligato/cn-infra
datasync/kvdbsync/local/local_proto_txn.go
NewProtoTxn
func NewProtoTxn(commit func(context.Context, map[string]datasync.ChangeValue) error) *ProtoTxn { return &ProtoTxn{ items: make(map[string]*protoTxnItem), commit: commit, } }
go
func NewProtoTxn(commit func(context.Context, map[string]datasync.ChangeValue) error) *ProtoTxn { return &ProtoTxn{ items: make(map[string]*protoTxnItem), commit: commit, } }
[ "func", "NewProtoTxn", "(", "commit", "func", "(", "context", ".", "Context", ",", "map", "[", "string", "]", "datasync", ".", "ChangeValue", ")", "error", ")", "*", "ProtoTxn", "{", "return", "&", "ProtoTxn", "{", "items", ":", "make", "(", "map", "[", "string", "]", "*", "protoTxnItem", ")", ",", "commit", ":", "commit", ",", "}", "\n", "}" ]
// NewProtoTxn is a constructor.
[ "NewProtoTxn", "is", "a", "constructor", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/kvdbsync/local/local_proto_txn.go#L50-L55
4,803
ligato/cn-infra
datasync/kvdbsync/local/local_proto_txn.go
Delete
func (txn *ProtoTxn) Delete(key string) keyval.ProtoTxn { txn.access.Lock() defer txn.access.Unlock() txn.items[key] = &protoTxnItem{delete: true} return txn }
go
func (txn *ProtoTxn) Delete(key string) keyval.ProtoTxn { txn.access.Lock() defer txn.access.Unlock() txn.items[key] = &protoTxnItem{delete: true} return txn }
[ "func", "(", "txn", "*", "ProtoTxn", ")", "Delete", "(", "key", "string", ")", "keyval", ".", "ProtoTxn", "{", "txn", ".", "access", ".", "Lock", "(", ")", "\n", "defer", "txn", ".", "access", ".", "Unlock", "(", ")", "\n\n", "txn", ".", "items", "[", "key", "]", "=", "&", "protoTxnItem", "{", "delete", ":", "true", "}", "\n\n", "return", "txn", "\n", "}" ]
// Delete adds delete operation into transaction.
[ "Delete", "adds", "delete", "operation", "into", "transaction", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/kvdbsync/local/local_proto_txn.go#L68-L75
4,804
ligato/cn-infra
examples/kafka-lib/syncproducer/syncproducer.go
sendMessage
func sendMessage(producer *client.SyncProducer, msg utils.Message) error { var ( msgKey []byte msgValue []byte ) // init message if msg.Key != "" { msgKey = []byte(msg.Key) } msgValue = []byte(msg.Text) // Demonstrate the use of SyncProducer.SendMsgByte() API. // The function doesn't return until the delivery status is known. _, err := producer.SendMsgByte(msg.Topic, msgKey, msgValue) if err != nil { logrus.DefaultLogger().Errorf("SendMsg Error: %v", err) return err } fmt.Println("message sent") return nil }
go
func sendMessage(producer *client.SyncProducer, msg utils.Message) error { var ( msgKey []byte msgValue []byte ) // init message if msg.Key != "" { msgKey = []byte(msg.Key) } msgValue = []byte(msg.Text) // Demonstrate the use of SyncProducer.SendMsgByte() API. // The function doesn't return until the delivery status is known. _, err := producer.SendMsgByte(msg.Topic, msgKey, msgValue) if err != nil { logrus.DefaultLogger().Errorf("SendMsg Error: %v", err) return err } fmt.Println("message sent") return nil }
[ "func", "sendMessage", "(", "producer", "*", "client", ".", "SyncProducer", ",", "msg", "utils", ".", "Message", ")", "error", "{", "var", "(", "msgKey", "[", "]", "byte", "\n", "msgValue", "[", "]", "byte", "\n", ")", "\n\n", "// init message", "if", "msg", ".", "Key", "!=", "\"", "\"", "{", "msgKey", "=", "[", "]", "byte", "(", "msg", ".", "Key", ")", "\n", "}", "\n", "msgValue", "=", "[", "]", "byte", "(", "msg", ".", "Text", ")", "\n\n", "// Demonstrate the use of SyncProducer.SendMsgByte() API.", "// The function doesn't return until the delivery status is known.", "_", ",", "err", ":=", "producer", ".", "SendMsgByte", "(", "msg", ".", "Topic", ",", "msgKey", ",", "msgValue", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "DefaultLogger", "(", ")", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// sendMessage demonstrates SyncProducer.SendMsgByte API to publish a single // message to a Kafka topic.
[ "sendMessage", "demonstrates", "SyncProducer", ".", "SendMsgByte", "API", "to", "publish", "a", "single", "message", "to", "a", "Kafka", "topic", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/kafka-lib/syncproducer/syncproducer.go#L111-L132
4,805
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
NewSyncPublisher
func (conn *BytesConnectionStr) NewSyncPublisher(topic string) (BytesPublisher, error) { return &bytesSyncPublisherKafka{conn, topic}, nil }
go
func (conn *BytesConnectionStr) NewSyncPublisher(topic string) (BytesPublisher, error) { return &bytesSyncPublisherKafka{conn, topic}, nil }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "NewSyncPublisher", "(", "topic", "string", ")", "(", "BytesPublisher", ",", "error", ")", "{", "return", "&", "bytesSyncPublisherKafka", "{", "conn", ",", "topic", "}", ",", "nil", "\n", "}" ]
// NewSyncPublisher creates a new instance of bytesSyncPublisherKafka that allows to publish sync kafka messages using common messaging API
[ "NewSyncPublisher", "creates", "a", "new", "instance", "of", "bytesSyncPublisherKafka", "that", "allows", "to", "publish", "sync", "kafka", "messages", "using", "common", "messaging", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L77-L79
4,806
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
NewAsyncPublisher
func (conn *BytesConnectionStr) NewAsyncPublisher(topic string, successClb func(*client.ProducerMessage), errorClb func(err *client.ProducerError)) (BytesPublisher, error) { return &bytesAsyncPublisherKafka{conn, topic, successClb, errorClb}, nil }
go
func (conn *BytesConnectionStr) NewAsyncPublisher(topic string, successClb func(*client.ProducerMessage), errorClb func(err *client.ProducerError)) (BytesPublisher, error) { return &bytesAsyncPublisherKafka{conn, topic, successClb, errorClb}, nil }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "NewAsyncPublisher", "(", "topic", "string", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errorClb", "func", "(", "err", "*", "client", ".", "ProducerError", ")", ")", "(", "BytesPublisher", ",", "error", ")", "{", "return", "&", "bytesAsyncPublisherKafka", "{", "conn", ",", "topic", ",", "successClb", ",", "errorClb", "}", ",", "nil", "\n", "}" ]
// NewAsyncPublisher creates a new instance of bytesAsyncPublisherKafka that allows to publish async kafka messages using common messaging API
[ "NewAsyncPublisher", "creates", "a", "new", "instance", "of", "bytesAsyncPublisherKafka", "that", "allows", "to", "publish", "async", "kafka", "messages", "using", "common", "messaging", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L82-L84
4,807
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
NewSyncPublisherToPartition
func (conn *BytesManualConnectionStr) NewSyncPublisherToPartition(topic string, partition int32) (BytesPublisher, error) { return &bytesManualSyncPublisherKafka{conn, topic, partition}, nil }
go
func (conn *BytesManualConnectionStr) NewSyncPublisherToPartition(topic string, partition int32) (BytesPublisher, error) { return &bytesManualSyncPublisherKafka{conn, topic, partition}, nil }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "NewSyncPublisherToPartition", "(", "topic", "string", ",", "partition", "int32", ")", "(", "BytesPublisher", ",", "error", ")", "{", "return", "&", "bytesManualSyncPublisherKafka", "{", "conn", ",", "topic", ",", "partition", "}", ",", "nil", "\n", "}" ]
// NewSyncPublisherToPartition creates a new instance of bytesSyncPublisherKafka that allows to publish sync kafka messages using common messaging API
[ "NewSyncPublisherToPartition", "creates", "a", "new", "instance", "of", "bytesSyncPublisherKafka", "that", "allows", "to", "publish", "sync", "kafka", "messages", "using", "common", "messaging", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L87-L89
4,808
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
NewAsyncPublisherToPartition
func (conn *BytesManualConnectionStr) NewAsyncPublisherToPartition(topic string, partition int32, successClb func(*client.ProducerMessage), errorClb func(err *client.ProducerError)) (BytesPublisher, error) { return &bytesManualAsyncPublisherKafka{conn, topic, partition, successClb, errorClb}, nil }
go
func (conn *BytesManualConnectionStr) NewAsyncPublisherToPartition(topic string, partition int32, successClb func(*client.ProducerMessage), errorClb func(err *client.ProducerError)) (BytesPublisher, error) { return &bytesManualAsyncPublisherKafka{conn, topic, partition, successClb, errorClb}, nil }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "NewAsyncPublisherToPartition", "(", "topic", "string", ",", "partition", "int32", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errorClb", "func", "(", "err", "*", "client", ".", "ProducerError", ")", ")", "(", "BytesPublisher", ",", "error", ")", "{", "return", "&", "bytesManualAsyncPublisherKafka", "{", "conn", ",", "topic", ",", "partition", ",", "successClb", ",", "errorClb", "}", ",", "nil", "\n", "}" ]
// NewAsyncPublisherToPartition creates a new instance of bytesAsyncPublisherKafka that allows to publish async kafka messages using common messaging API
[ "NewAsyncPublisherToPartition", "creates", "a", "new", "instance", "of", "bytesAsyncPublisherKafka", "that", "allows", "to", "publish", "async", "kafka", "messages", "using", "common", "messaging", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L92-L94
4,809
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
ConsumeTopic
func (conn *BytesConnectionStr) ConsumeTopic(msgClb func(message *client.ConsumerMessage), topics ...string) error { conn.multiplexer.rwlock.Lock() defer conn.multiplexer.rwlock.Unlock() if conn.multiplexer.started { return fmt.Errorf("ConsumeTopic can be called only if the multiplexer has not been started yet") } for _, topic := range topics { // check if we have already consumed the topic var found bool var subs *consumerSubscription LoopSubs: for _, subscription := range conn.multiplexer.mapping { if subscription.manual == true { // do not mix dynamic and manual mode continue } if subscription.topic == topic { found = true subs = subscription break LoopSubs } } if !found { subs = &consumerSubscription{ manual: false, // non-manual example topic: topic, connectionName: conn.name, byteConsMsg: msgClb, } // subscribe new topic conn.multiplexer.mapping = append(conn.multiplexer.mapping, subs) } // add subscription to consumerList subs.byteConsMsg = msgClb } return nil }
go
func (conn *BytesConnectionStr) ConsumeTopic(msgClb func(message *client.ConsumerMessage), topics ...string) error { conn.multiplexer.rwlock.Lock() defer conn.multiplexer.rwlock.Unlock() if conn.multiplexer.started { return fmt.Errorf("ConsumeTopic can be called only if the multiplexer has not been started yet") } for _, topic := range topics { // check if we have already consumed the topic var found bool var subs *consumerSubscription LoopSubs: for _, subscription := range conn.multiplexer.mapping { if subscription.manual == true { // do not mix dynamic and manual mode continue } if subscription.topic == topic { found = true subs = subscription break LoopSubs } } if !found { subs = &consumerSubscription{ manual: false, // non-manual example topic: topic, connectionName: conn.name, byteConsMsg: msgClb, } // subscribe new topic conn.multiplexer.mapping = append(conn.multiplexer.mapping, subs) } // add subscription to consumerList subs.byteConsMsg = msgClb } return nil }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "ConsumeTopic", "(", "msgClb", "func", "(", "message", "*", "client", ".", "ConsumerMessage", ")", ",", "topics", "...", "string", ")", "error", "{", "conn", ".", "multiplexer", ".", "rwlock", ".", "Lock", "(", ")", "\n", "defer", "conn", ".", "multiplexer", ".", "rwlock", ".", "Unlock", "(", ")", "\n\n", "if", "conn", ".", "multiplexer", ".", "started", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "topic", ":=", "range", "topics", "{", "// check if we have already consumed the topic", "var", "found", "bool", "\n", "var", "subs", "*", "consumerSubscription", "\n", "LoopSubs", ":", "for", "_", ",", "subscription", ":=", "range", "conn", ".", "multiplexer", ".", "mapping", "{", "if", "subscription", ".", "manual", "==", "true", "{", "// do not mix dynamic and manual mode", "continue", "\n", "}", "\n", "if", "subscription", ".", "topic", "==", "topic", "{", "found", "=", "true", "\n", "subs", "=", "subscription", "\n", "break", "LoopSubs", "\n", "}", "\n", "}", "\n\n", "if", "!", "found", "{", "subs", "=", "&", "consumerSubscription", "{", "manual", ":", "false", ",", "// non-manual example", "topic", ":", "topic", ",", "connectionName", ":", "conn", ".", "name", ",", "byteConsMsg", ":", "msgClb", ",", "}", "\n", "// subscribe new topic", "conn", ".", "multiplexer", ".", "mapping", "=", "append", "(", "conn", ".", "multiplexer", ".", "mapping", ",", "subs", ")", "\n", "}", "\n\n", "// add subscription to consumerList", "subs", ".", "byteConsMsg", "=", "msgClb", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ConsumeTopic is called to start consuming of a topic. // Function can be called until the multiplexer is started, it returns an error otherwise. // The provided channel should be buffered, otherwise messages might be lost.
[ "ConsumeTopic", "is", "called", "to", "start", "consuming", "of", "a", "topic", ".", "Function", "can", "be", "called", "until", "the", "multiplexer", "is", "started", "it", "returns", "an", "error", "otherwise", ".", "The", "provided", "channel", "should", "be", "buffered", "otherwise", "messages", "might", "be", "lost", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L99-L140
4,810
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
StartPostInitConsumer
func (conn *BytesManualConnectionStr) StartPostInitConsumer(topic string, partition int32, offset int64) (*sarama.PartitionConsumer, error) { multiplexer := conn.multiplexer multiplexer.WithFields(logging.Fields{"topic": topic}).Debugf("Post-init consuming started") if multiplexer.Consumer == nil || multiplexer.Consumer.SConsumer == nil { multiplexer.Warn("Unable to start post-init Consumer, client not available in the mux") return nil, nil } // Consumer that reads topic/partition/offset. Throws error if offset is 'in the future' (message with offset does not exist yet) partitionConsumer, err := multiplexer.Consumer.SConsumer.ConsumePartition(topic, partition, offset) if err != nil { return nil, err } multiplexer.Consumer.StartConsumerManualHandlers(partitionConsumer) return &partitionConsumer, nil }
go
func (conn *BytesManualConnectionStr) StartPostInitConsumer(topic string, partition int32, offset int64) (*sarama.PartitionConsumer, error) { multiplexer := conn.multiplexer multiplexer.WithFields(logging.Fields{"topic": topic}).Debugf("Post-init consuming started") if multiplexer.Consumer == nil || multiplexer.Consumer.SConsumer == nil { multiplexer.Warn("Unable to start post-init Consumer, client not available in the mux") return nil, nil } // Consumer that reads topic/partition/offset. Throws error if offset is 'in the future' (message with offset does not exist yet) partitionConsumer, err := multiplexer.Consumer.SConsumer.ConsumePartition(topic, partition, offset) if err != nil { return nil, err } multiplexer.Consumer.StartConsumerManualHandlers(partitionConsumer) return &partitionConsumer, nil }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "StartPostInitConsumer", "(", "topic", "string", ",", "partition", "int32", ",", "offset", "int64", ")", "(", "*", "sarama", ".", "PartitionConsumer", ",", "error", ")", "{", "multiplexer", ":=", "conn", ".", "multiplexer", "\n", "multiplexer", ".", "WithFields", "(", "logging", ".", "Fields", "{", "\"", "\"", ":", "topic", "}", ")", ".", "Debugf", "(", "\"", "\"", ")", "\n\n", "if", "multiplexer", ".", "Consumer", "==", "nil", "||", "multiplexer", ".", "Consumer", ".", "SConsumer", "==", "nil", "{", "multiplexer", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n\n", "// Consumer that reads topic/partition/offset. Throws error if offset is 'in the future' (message with offset does not exist yet)", "partitionConsumer", ",", "err", ":=", "multiplexer", ".", "Consumer", ".", "SConsumer", ".", "ConsumePartition", "(", "topic", ",", "partition", ",", "offset", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "multiplexer", ".", "Consumer", ".", "StartConsumerManualHandlers", "(", "partitionConsumer", ")", "\n\n", "return", "&", "partitionConsumer", ",", "nil", "\n", "}" ]
// StartPostInitConsumer allows to start a new partition consumer after mux is initialized
[ "StartPostInitConsumer", "allows", "to", "start", "a", "new", "partition", "consumer", "after", "mux", "is", "initialized" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L197-L214
4,811
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
StopConsuming
func (conn *BytesConnectionStr) StopConsuming(topic string) error { return conn.multiplexer.stopConsuming(topic, conn.name) }
go
func (conn *BytesConnectionStr) StopConsuming(topic string) error { return conn.multiplexer.stopConsuming(topic, conn.name) }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "StopConsuming", "(", "topic", "string", ")", "error", "{", "return", "conn", ".", "multiplexer", ".", "stopConsuming", "(", "topic", ",", "conn", ".", "name", ")", "\n", "}" ]
// StopConsuming cancels the previously created subscription for consuming the topic.
[ "StopConsuming", "cancels", "the", "previously", "created", "subscription", "for", "consuming", "the", "topic", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L217-L219
4,812
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendSyncMessage
func (conn *BytesConnectionStr) SendSyncMessage(topic string, key client.Encoder, value client.Encoder) (offset int64, err error) { msg, err := conn.multiplexer.hashSyncProducer.SendMsgToPartition(topic, DefPartition, key, value) if err != nil { return 0, err } return msg.Offset, err }
go
func (conn *BytesConnectionStr) SendSyncMessage(topic string, key client.Encoder, value client.Encoder) (offset int64, err error) { msg, err := conn.multiplexer.hashSyncProducer.SendMsgToPartition(topic, DefPartition, key, value) if err != nil { return 0, err } return msg.Offset, err }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "SendSyncMessage", "(", "topic", "string", ",", "key", "client", ".", "Encoder", ",", "value", "client", ".", "Encoder", ")", "(", "offset", "int64", ",", "err", "error", ")", "{", "msg", ",", "err", ":=", "conn", ".", "multiplexer", ".", "hashSyncProducer", ".", "SendMsgToPartition", "(", "topic", ",", "DefPartition", ",", "key", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "msg", ".", "Offset", ",", "err", "\n", "}" ]
//SendSyncMessage sends a message using the sync API and default partitioner
[ "SendSyncMessage", "sends", "a", "message", "using", "the", "sync", "API", "and", "default", "partitioner" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L227-L233
4,813
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendAsyncMessage
func (conn *BytesConnectionStr) SendAsyncMessage(topic string, key client.Encoder, value client.Encoder, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { auxMeta := &asyncMeta{successClb: successClb, errorClb: errClb, usersMeta: meta} conn.multiplexer.hashAsyncProducer.SendMsgToPartition(topic, DefPartition, key, value, auxMeta) }
go
func (conn *BytesConnectionStr) SendAsyncMessage(topic string, key client.Encoder, value client.Encoder, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { auxMeta := &asyncMeta{successClb: successClb, errorClb: errClb, usersMeta: meta} conn.multiplexer.hashAsyncProducer.SendMsgToPartition(topic, DefPartition, key, value, auxMeta) }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "SendAsyncMessage", "(", "topic", "string", ",", "key", "client", ".", "Encoder", ",", "value", "client", ".", "Encoder", ",", "meta", "interface", "{", "}", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errClb", "func", "(", "*", "client", ".", "ProducerError", ")", ")", "{", "auxMeta", ":=", "&", "asyncMeta", "{", "successClb", ":", "successClb", ",", "errorClb", ":", "errClb", ",", "usersMeta", ":", "meta", "}", "\n", "conn", ".", "multiplexer", ".", "hashAsyncProducer", ".", "SendMsgToPartition", "(", "topic", ",", "DefPartition", ",", "key", ",", "value", ",", "auxMeta", ")", "\n", "}" ]
// SendAsyncMessage sends a message using the async API and default partitioner
[ "SendAsyncMessage", "sends", "a", "message", "using", "the", "async", "API", "and", "default", "partitioner" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L236-L239
4,814
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendSyncMessageToPartition
func (conn *BytesManualConnectionStr) SendSyncMessageToPartition(topic string, partition int32, key client.Encoder, value client.Encoder) (offset int64, err error) { msg, err := conn.multiplexer.manSyncProducer.SendMsgToPartition(topic, partition, key, value) if err != nil { return 0, err } return msg.Offset, err }
go
func (conn *BytesManualConnectionStr) SendSyncMessageToPartition(topic string, partition int32, key client.Encoder, value client.Encoder) (offset int64, err error) { msg, err := conn.multiplexer.manSyncProducer.SendMsgToPartition(topic, partition, key, value) if err != nil { return 0, err } return msg.Offset, err }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "SendSyncMessageToPartition", "(", "topic", "string", ",", "partition", "int32", ",", "key", "client", ".", "Encoder", ",", "value", "client", ".", "Encoder", ")", "(", "offset", "int64", ",", "err", "error", ")", "{", "msg", ",", "err", ":=", "conn", ".", "multiplexer", ".", "manSyncProducer", ".", "SendMsgToPartition", "(", "topic", ",", "partition", ",", "key", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "msg", ".", "Offset", ",", "err", "\n", "}" ]
//SendSyncMessageToPartition sends a message using the sync API and default partitioner
[ "SendSyncMessageToPartition", "sends", "a", "message", "using", "the", "sync", "API", "and", "default", "partitioner" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L242-L248
4,815
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendAsyncMessageToPartition
func (conn *BytesManualConnectionStr) SendAsyncMessageToPartition(topic string, partition int32, key client.Encoder, value client.Encoder, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { auxMeta := &asyncMeta{successClb: successClb, errorClb: errClb, usersMeta: meta} conn.multiplexer.manAsyncProducer.SendMsgToPartition(topic, partition, key, value, auxMeta) }
go
func (conn *BytesManualConnectionStr) SendAsyncMessageToPartition(topic string, partition int32, key client.Encoder, value client.Encoder, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { auxMeta := &asyncMeta{successClb: successClb, errorClb: errClb, usersMeta: meta} conn.multiplexer.manAsyncProducer.SendMsgToPartition(topic, partition, key, value, auxMeta) }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "SendAsyncMessageToPartition", "(", "topic", "string", ",", "partition", "int32", ",", "key", "client", ".", "Encoder", ",", "value", "client", ".", "Encoder", ",", "meta", "interface", "{", "}", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errClb", "func", "(", "*", "client", ".", "ProducerError", ")", ")", "{", "auxMeta", ":=", "&", "asyncMeta", "{", "successClb", ":", "successClb", ",", "errorClb", ":", "errClb", ",", "usersMeta", ":", "meta", "}", "\n", "conn", ".", "multiplexer", ".", "manAsyncProducer", ".", "SendMsgToPartition", "(", "topic", ",", "partition", ",", "key", ",", "value", ",", "auxMeta", ")", "\n", "}" ]
// SendAsyncMessageToPartition sends a message using the async API and default partitioner
[ "SendAsyncMessageToPartition", "sends", "a", "message", "using", "the", "async", "API", "and", "default", "partitioner" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L251-L254
4,816
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendSyncByte
func (conn *BytesConnectionStr) SendSyncByte(topic string, key []byte, value []byte) (offset int64, err error) { return conn.SendSyncMessage(topic, sarama.ByteEncoder(key), sarama.ByteEncoder(value)) }
go
func (conn *BytesConnectionStr) SendSyncByte(topic string, key []byte, value []byte) (offset int64, err error) { return conn.SendSyncMessage(topic, sarama.ByteEncoder(key), sarama.ByteEncoder(value)) }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "SendSyncByte", "(", "topic", "string", ",", "key", "[", "]", "byte", ",", "value", "[", "]", "byte", ")", "(", "offset", "int64", ",", "err", "error", ")", "{", "return", "conn", ".", "SendSyncMessage", "(", "topic", ",", "sarama", ".", "ByteEncoder", "(", "key", ")", ",", "sarama", ".", "ByteEncoder", "(", "value", ")", ")", "\n", "}" ]
// SendSyncByte sends a message that uses byte encoder using the sync API
[ "SendSyncByte", "sends", "a", "message", "that", "uses", "byte", "encoder", "using", "the", "sync", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L257-L259
4,817
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendSyncString
func (conn *BytesConnectionStr) SendSyncString(topic string, key string, value string) (offset int64, err error) { return conn.SendSyncMessage(topic, sarama.StringEncoder(key), sarama.StringEncoder(value)) }
go
func (conn *BytesConnectionStr) SendSyncString(topic string, key string, value string) (offset int64, err error) { return conn.SendSyncMessage(topic, sarama.StringEncoder(key), sarama.StringEncoder(value)) }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "SendSyncString", "(", "topic", "string", ",", "key", "string", ",", "value", "string", ")", "(", "offset", "int64", ",", "err", "error", ")", "{", "return", "conn", ".", "SendSyncMessage", "(", "topic", ",", "sarama", ".", "StringEncoder", "(", "key", ")", ",", "sarama", ".", "StringEncoder", "(", "value", ")", ")", "\n", "}" ]
// SendSyncString sends a message that uses string encoder using the sync API
[ "SendSyncString", "sends", "a", "message", "that", "uses", "string", "encoder", "using", "the", "sync", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L262-L264
4,818
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendSyncStringToPartition
func (conn *BytesManualConnectionStr) SendSyncStringToPartition(topic string, partition int32, key string, value string) (offset int64, err error) { return conn.SendSyncMessageToPartition(topic, partition, sarama.StringEncoder(key), sarama.StringEncoder(value)) }
go
func (conn *BytesManualConnectionStr) SendSyncStringToPartition(topic string, partition int32, key string, value string) (offset int64, err error) { return conn.SendSyncMessageToPartition(topic, partition, sarama.StringEncoder(key), sarama.StringEncoder(value)) }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "SendSyncStringToPartition", "(", "topic", "string", ",", "partition", "int32", ",", "key", "string", ",", "value", "string", ")", "(", "offset", "int64", ",", "err", "error", ")", "{", "return", "conn", ".", "SendSyncMessageToPartition", "(", "topic", ",", "partition", ",", "sarama", ".", "StringEncoder", "(", "key", ")", ",", "sarama", ".", "StringEncoder", "(", "value", ")", ")", "\n", "}" ]
// SendSyncStringToPartition sends a message that uses string encoder using the sync API to custom partition
[ "SendSyncStringToPartition", "sends", "a", "message", "that", "uses", "string", "encoder", "using", "the", "sync", "API", "to", "custom", "partition" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L267-L269
4,819
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendAsyncByte
func (conn *BytesConnectionStr) SendAsyncByte(topic string, key []byte, value []byte, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { conn.SendAsyncMessage(topic, sarama.ByteEncoder(key), sarama.ByteEncoder(value), meta, successClb, errClb) }
go
func (conn *BytesConnectionStr) SendAsyncByte(topic string, key []byte, value []byte, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { conn.SendAsyncMessage(topic, sarama.ByteEncoder(key), sarama.ByteEncoder(value), meta, successClb, errClb) }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "SendAsyncByte", "(", "topic", "string", ",", "key", "[", "]", "byte", ",", "value", "[", "]", "byte", ",", "meta", "interface", "{", "}", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errClb", "func", "(", "*", "client", ".", "ProducerError", ")", ")", "{", "conn", ".", "SendAsyncMessage", "(", "topic", ",", "sarama", ".", "ByteEncoder", "(", "key", ")", ",", "sarama", ".", "ByteEncoder", "(", "value", ")", ",", "meta", ",", "successClb", ",", "errClb", ")", "\n", "}" ]
// SendAsyncByte sends a message that uses byte encoder using the async API
[ "SendAsyncByte", "sends", "a", "message", "that", "uses", "byte", "encoder", "using", "the", "async", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L272-L274
4,820
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendAsyncString
func (conn *BytesConnectionStr) SendAsyncString(topic string, key string, value string, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { conn.SendAsyncMessage(topic, sarama.StringEncoder(key), sarama.StringEncoder(value), meta, successClb, errClb) }
go
func (conn *BytesConnectionStr) SendAsyncString(topic string, key string, value string, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { conn.SendAsyncMessage(topic, sarama.StringEncoder(key), sarama.StringEncoder(value), meta, successClb, errClb) }
[ "func", "(", "conn", "*", "BytesConnectionStr", ")", "SendAsyncString", "(", "topic", "string", ",", "key", "string", ",", "value", "string", ",", "meta", "interface", "{", "}", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errClb", "func", "(", "*", "client", ".", "ProducerError", ")", ")", "{", "conn", ".", "SendAsyncMessage", "(", "topic", ",", "sarama", ".", "StringEncoder", "(", "key", ")", ",", "sarama", ".", "StringEncoder", "(", "value", ")", ",", "meta", ",", "successClb", ",", "errClb", ")", "\n", "}" ]
// SendAsyncString sends a message that uses string encoder using the async API
[ "SendAsyncString", "sends", "a", "message", "that", "uses", "string", "encoder", "using", "the", "async", "API" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L277-L279
4,821
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
SendAsyncStringToPartition
func (conn *BytesManualConnectionStr) SendAsyncStringToPartition(topic string, partition int32, key string, value string, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { conn.SendAsyncMessageToPartition(topic, partition, sarama.StringEncoder(key), sarama.StringEncoder(value), meta, successClb, errClb) }
go
func (conn *BytesManualConnectionStr) SendAsyncStringToPartition(topic string, partition int32, key string, value string, meta interface{}, successClb func(*client.ProducerMessage), errClb func(*client.ProducerError)) { conn.SendAsyncMessageToPartition(topic, partition, sarama.StringEncoder(key), sarama.StringEncoder(value), meta, successClb, errClb) }
[ "func", "(", "conn", "*", "BytesManualConnectionStr", ")", "SendAsyncStringToPartition", "(", "topic", "string", ",", "partition", "int32", ",", "key", "string", ",", "value", "string", ",", "meta", "interface", "{", "}", ",", "successClb", "func", "(", "*", "client", ".", "ProducerMessage", ")", ",", "errClb", "func", "(", "*", "client", ".", "ProducerError", ")", ")", "{", "conn", ".", "SendAsyncMessageToPartition", "(", "topic", ",", "partition", ",", "sarama", ".", "StringEncoder", "(", "key", ")", ",", "sarama", ".", "StringEncoder", "(", "value", ")", ",", "meta", ",", "successClb", ",", "errClb", ")", "\n", "}" ]
// SendAsyncStringToPartition sends a message that uses string encoder using the async API to custom partition
[ "SendAsyncStringToPartition", "sends", "a", "message", "that", "uses", "string", "encoder", "using", "the", "async", "API", "to", "custom", "partition" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L282-L284
4,822
ligato/cn-infra
messaging/kafka/mux/bytes_connection.go
CommitOffsets
func (conn *BytesConnectionFields) CommitOffsets() error { if conn.multiplexer != nil && conn.multiplexer.Consumer != nil { return conn.multiplexer.Consumer.CommitOffsets() } return fmt.Errorf("cannot commit offsets, consumer not available") }
go
func (conn *BytesConnectionFields) CommitOffsets() error { if conn.multiplexer != nil && conn.multiplexer.Consumer != nil { return conn.multiplexer.Consumer.CommitOffsets() } return fmt.Errorf("cannot commit offsets, consumer not available") }
[ "func", "(", "conn", "*", "BytesConnectionFields", ")", "CommitOffsets", "(", ")", "error", "{", "if", "conn", ".", "multiplexer", "!=", "nil", "&&", "conn", ".", "multiplexer", ".", "Consumer", "!=", "nil", "{", "return", "conn", ".", "multiplexer", ".", "Consumer", ".", "CommitOffsets", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// CommitOffsets manually commits message offsets
[ "CommitOffsets", "manually", "commits", "message", "offsets" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/bytes_connection.go#L318-L323
4,823
ligato/cn-infra
db/keyval/kvproto/proto_broker_impl.go
NewProtoWrapper
func NewProtoWrapper(db keyval.CoreBrokerWatcher, serializer ...keyval.Serializer) *ProtoWrapper { if len(serializer) > 0 { return &ProtoWrapper{db, serializer[0]} } return &ProtoWrapper{db, &keyval.SerializerProto{}} }
go
func NewProtoWrapper(db keyval.CoreBrokerWatcher, serializer ...keyval.Serializer) *ProtoWrapper { if len(serializer) > 0 { return &ProtoWrapper{db, serializer[0]} } return &ProtoWrapper{db, &keyval.SerializerProto{}} }
[ "func", "NewProtoWrapper", "(", "db", "keyval", ".", "CoreBrokerWatcher", ",", "serializer", "...", "keyval", ".", "Serializer", ")", "*", "ProtoWrapper", "{", "if", "len", "(", "serializer", ")", ">", "0", "{", "return", "&", "ProtoWrapper", "{", "db", ",", "serializer", "[", "0", "]", "}", "\n", "}", "\n", "return", "&", "ProtoWrapper", "{", "db", ",", "&", "keyval", ".", "SerializerProto", "{", "}", "}", "\n", "}" ]
// NewProtoWrapper initializes proto decorator. // The default serializer is used - SerializerProto.
[ "NewProtoWrapper", "initializes", "proto", "decorator", ".", "The", "default", "serializer", "is", "used", "-", "SerializerProto", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/kvproto/proto_broker_impl.go#L55-L60
4,824
ligato/cn-infra
db/keyval/kvproto/proto_broker_impl.go
NewProtoWrapperWithSerializer
func NewProtoWrapperWithSerializer(db keyval.CoreBrokerWatcher, serializer keyval.Serializer) *ProtoWrapper { // OBSOLETE, use NewProtoWrapper return NewProtoWrapper(db, serializer) }
go
func NewProtoWrapperWithSerializer(db keyval.CoreBrokerWatcher, serializer keyval.Serializer) *ProtoWrapper { // OBSOLETE, use NewProtoWrapper return NewProtoWrapper(db, serializer) }
[ "func", "NewProtoWrapperWithSerializer", "(", "db", "keyval", ".", "CoreBrokerWatcher", ",", "serializer", "keyval", ".", "Serializer", ")", "*", "ProtoWrapper", "{", "// OBSOLETE, use NewProtoWrapper", "return", "NewProtoWrapper", "(", "db", ",", "serializer", ")", "\n", "}" ]
// NewProtoWrapperWithSerializer initializes proto decorator with the specified // serializer.
[ "NewProtoWrapperWithSerializer", "initializes", "proto", "decorator", "with", "the", "specified", "serializer", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/kvproto/proto_broker_impl.go#L64-L67
4,825
ligato/cn-infra
db/keyval/kvproto/proto_broker_impl.go
NewWatcher
func (db *ProtoWrapper) NewWatcher(prefix string) keyval.ProtoWatcher { return &protoWatcher{db.broker.NewWatcher(prefix), db.serializer} }
go
func (db *ProtoWrapper) NewWatcher(prefix string) keyval.ProtoWatcher { return &protoWatcher{db.broker.NewWatcher(prefix), db.serializer} }
[ "func", "(", "db", "*", "ProtoWrapper", ")", "NewWatcher", "(", "prefix", "string", ")", "keyval", ".", "ProtoWatcher", "{", "return", "&", "protoWatcher", "{", "db", ".", "broker", ".", "NewWatcher", "(", "prefix", ")", ",", "db", ".", "serializer", "}", "\n", "}" ]
// NewWatcher creates a new instance of the proxy that shares the underlying // connection and allows subscribing for watching of the changes.
[ "NewWatcher", "creates", "a", "new", "instance", "of", "the", "proxy", "that", "shares", "the", "underlying", "connection", "and", "allows", "subscribing", "for", "watching", "of", "the", "changes", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/kvproto/proto_broker_impl.go#L84-L86
4,826
ligato/cn-infra
health/probe/prometheus_probe.go
getServiceHealth
func (p *Plugin) getServiceHealth() float64 { agentStatus := p.StatusCheck.GetAgentStatus() // Adapt Ligato status code for now. // TODO: Consolidate with that from the "Common Container Telemetry" proposal. health := float64(agentStatus.State) p.Log.Infof("ServiceHealth: %v", health) return health }
go
func (p *Plugin) getServiceHealth() float64 { agentStatus := p.StatusCheck.GetAgentStatus() // Adapt Ligato status code for now. // TODO: Consolidate with that from the "Common Container Telemetry" proposal. health := float64(agentStatus.State) p.Log.Infof("ServiceHealth: %v", health) return health }
[ "func", "(", "p", "*", "Plugin", ")", "getServiceHealth", "(", ")", "float64", "{", "agentStatus", ":=", "p", ".", "StatusCheck", ".", "GetAgentStatus", "(", ")", "\n", "// Adapt Ligato status code for now.", "// TODO: Consolidate with that from the \"Common Container Telemetry\" proposal.", "health", ":=", "float64", "(", "agentStatus", ".", "State", ")", "\n", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "health", ")", "\n", "return", "health", "\n", "}" ]
// getServiceHealth returns agent health status
[ "getServiceHealth", "returns", "agent", "health", "status" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/health/probe/prometheus_probe.go#L105-L112
4,827
ligato/cn-infra
health/probe/prometheus_probe.go
getDependencyHealth
func (p *Plugin) getDependencyHealth(pluginName string, pluginStatus *status.PluginStatus) func() float64 { p.Log.Infof("DependencyHealth for plugin %v: %v", pluginName, float64(pluginStatus.State)) return func() float64 { health := float64(pluginStatus.State) p.Log.Infof("Dependency Health %v: %v", pluginName, health) return health } }
go
func (p *Plugin) getDependencyHealth(pluginName string, pluginStatus *status.PluginStatus) func() float64 { p.Log.Infof("DependencyHealth for plugin %v: %v", pluginName, float64(pluginStatus.State)) return func() float64 { health := float64(pluginStatus.State) p.Log.Infof("Dependency Health %v: %v", pluginName, health) return health } }
[ "func", "(", "p", "*", "Plugin", ")", "getDependencyHealth", "(", "pluginName", "string", ",", "pluginStatus", "*", "status", ".", "PluginStatus", ")", "func", "(", ")", "float64", "{", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "pluginName", ",", "float64", "(", "pluginStatus", ".", "State", ")", ")", "\n\n", "return", "func", "(", ")", "float64", "{", "health", ":=", "float64", "(", "pluginStatus", ".", "State", ")", "\n", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "pluginName", ",", "health", ")", "\n", "return", "health", "\n", "}", "\n", "}" ]
// getDependencyHealth returns plugin health status
[ "getDependencyHealth", "returns", "plugin", "health", "status" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/health/probe/prometheus_probe.go#L115-L123
4,828
ligato/cn-infra
examples/cryptodata-proto-plugin/main.go
watchChanges
func (plugin *ExamplePlugin) watchChanges(x datasync.ProtoWatchResp) { message := &ipsec.TunnelInterfaces{} err := x.GetValue(message) if err == nil { plugin.Log.Infof("Got watch message %v", message) } }
go
func (plugin *ExamplePlugin) watchChanges(x datasync.ProtoWatchResp) { message := &ipsec.TunnelInterfaces{} err := x.GetValue(message) if err == nil { plugin.Log.Infof("Got watch message %v", message) } }
[ "func", "(", "plugin", "*", "ExamplePlugin", ")", "watchChanges", "(", "x", "datasync", ".", "ProtoWatchResp", ")", "{", "message", ":=", "&", "ipsec", ".", "TunnelInterfaces", "{", "}", "\n", "err", ":=", "x", ".", "GetValue", "(", "message", ")", "\n", "if", "err", "==", "nil", "{", "plugin", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "message", ")", "\n", "}", "\n", "}" ]
// watchChanges is watching for changes in DB
[ "watchChanges", "is", "watching", "for", "changes", "in", "DB" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/cryptodata-proto-plugin/main.go#L175-L181
4,829
ligato/cn-infra
db/cryptodata/plugin.go
Init
func (p *Plugin) Init() (err error) { var config Config found, err := p.Cfg.LoadValue(&config) if err != nil { return err } if !found { p.Log.Info("cryptodata config not found, skip loading this plugin") p.disabled = true return nil } // Read client config and create it clientConfig := ClientConfig{} for _, file := range config.PrivateKeyFiles { bytes, err := ioutil.ReadFile(file) if err != nil { p.Log.Infof("%v", err) return err } for { block, rest := pem.Decode(bytes) if block == nil { break } privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { p.Log.Infof("%v", err) return err } err = privateKey.Validate() if err != nil { p.Log.Infof("%v", err) return err } privateKey.Precompute() clientConfig.PrivateKeys = append(clientConfig.PrivateKeys, privateKey) if rest == nil { break } bytes = rest } } p.ClientAPI = NewClient(clientConfig) return }
go
func (p *Plugin) Init() (err error) { var config Config found, err := p.Cfg.LoadValue(&config) if err != nil { return err } if !found { p.Log.Info("cryptodata config not found, skip loading this plugin") p.disabled = true return nil } // Read client config and create it clientConfig := ClientConfig{} for _, file := range config.PrivateKeyFiles { bytes, err := ioutil.ReadFile(file) if err != nil { p.Log.Infof("%v", err) return err } for { block, rest := pem.Decode(bytes) if block == nil { break } privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { p.Log.Infof("%v", err) return err } err = privateKey.Validate() if err != nil { p.Log.Infof("%v", err) return err } privateKey.Precompute() clientConfig.PrivateKeys = append(clientConfig.PrivateKeys, privateKey) if rest == nil { break } bytes = rest } } p.ClientAPI = NewClient(clientConfig) return }
[ "func", "(", "p", "*", "Plugin", ")", "Init", "(", ")", "(", "err", "error", ")", "{", "var", "config", "Config", "\n", "found", ",", "err", ":=", "p", ".", "Cfg", ".", "LoadValue", "(", "&", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "found", "{", "p", ".", "Log", ".", "Info", "(", "\"", "\"", ")", "\n", "p", ".", "disabled", "=", "true", "\n", "return", "nil", "\n", "}", "\n\n", "// Read client config and create it", "clientConfig", ":=", "ClientConfig", "{", "}", "\n", "for", "_", ",", "file", ":=", "range", "config", ".", "PrivateKeyFiles", "{", "bytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "for", "{", "block", ",", "rest", ":=", "pem", ".", "Decode", "(", "bytes", ")", "\n", "if", "block", "==", "nil", "{", "break", "\n", "}", "\n\n", "privateKey", ",", "err", ":=", "x509", ".", "ParsePKCS1PrivateKey", "(", "block", ".", "Bytes", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "err", "=", "privateKey", ".", "Validate", "(", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "privateKey", ".", "Precompute", "(", ")", "\n", "clientConfig", ".", "PrivateKeys", "=", "append", "(", "clientConfig", ".", "PrivateKeys", ",", "privateKey", ")", "\n\n", "if", "rest", "==", "nil", "{", "break", "\n", "}", "\n\n", "bytes", "=", "rest", "\n", "}", "\n", "}", "\n\n", "p", ".", "ClientAPI", "=", "NewClient", "(", "clientConfig", ")", "\n", "return", "\n", "}" ]
// Init initializes cryptodata plugin.
[ "Init", "initializes", "cryptodata", "plugin", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/cryptodata/plugin.go#L45-L98
4,830
ligato/cn-infra
messaging/kafka/client/messages.go
NewProtoConsumerMessage
func NewProtoConsumerMessage(msg *ConsumerMessage, serializer keyval.Serializer) *ProtoConsumerMessage { return &ProtoConsumerMessage{msg, serializer} }
go
func NewProtoConsumerMessage(msg *ConsumerMessage, serializer keyval.Serializer) *ProtoConsumerMessage { return &ProtoConsumerMessage{msg, serializer} }
[ "func", "NewProtoConsumerMessage", "(", "msg", "*", "ConsumerMessage", ",", "serializer", "keyval", ".", "Serializer", ")", "*", "ProtoConsumerMessage", "{", "return", "&", "ProtoConsumerMessage", "{", "msg", ",", "serializer", "}", "\n", "}" ]
// NewProtoConsumerMessage creates new instance of ProtoConsumerMessage
[ "NewProtoConsumerMessage", "creates", "new", "instance", "of", "ProtoConsumerMessage" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/client/messages.go#L79-L81
4,831
ligato/cn-infra
messaging/kafka/client/messages.go
GetValue
func (cm *ProtoConsumerMessage) GetValue(msg proto.Message) error { err := cm.serializer.Unmarshal(cm.ConsumerMessage.GetValue(), msg) if err != nil { return err } return nil }
go
func (cm *ProtoConsumerMessage) GetValue(msg proto.Message) error { err := cm.serializer.Unmarshal(cm.ConsumerMessage.GetValue(), msg) if err != nil { return err } return nil }
[ "func", "(", "cm", "*", "ProtoConsumerMessage", ")", "GetValue", "(", "msg", "proto", ".", "Message", ")", "error", "{", "err", ":=", "cm", ".", "serializer", ".", "Unmarshal", "(", "cm", ".", "ConsumerMessage", ".", "GetValue", "(", ")", ",", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetValue returns the value associated with the message.
[ "GetValue", "returns", "the", "value", "associated", "with", "the", "message", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/client/messages.go#L104-L110
4,832
ligato/cn-infra
messaging/kafka/client/messages.go
GetPrevValue
func (cm *ProtoConsumerMessage) GetPrevValue(msg proto.Message) (prevValueExist bool, err error) { prevVal := cm.ConsumerMessage.GetPrevValue() if prevVal == nil { return false, nil } err = cm.serializer.Unmarshal(prevVal, msg) if err != nil { return true, err } return true, nil }
go
func (cm *ProtoConsumerMessage) GetPrevValue(msg proto.Message) (prevValueExist bool, err error) { prevVal := cm.ConsumerMessage.GetPrevValue() if prevVal == nil { return false, nil } err = cm.serializer.Unmarshal(prevVal, msg) if err != nil { return true, err } return true, nil }
[ "func", "(", "cm", "*", "ProtoConsumerMessage", ")", "GetPrevValue", "(", "msg", "proto", ".", "Message", ")", "(", "prevValueExist", "bool", ",", "err", "error", ")", "{", "prevVal", ":=", "cm", ".", "ConsumerMessage", ".", "GetPrevValue", "(", ")", "\n", "if", "prevVal", "==", "nil", "{", "return", "false", ",", "nil", "\n", "}", "\n", "err", "=", "cm", ".", "serializer", ".", "Unmarshal", "(", "prevVal", ",", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// GetPrevValue returns the previous value associated with the latest message.
[ "GetPrevValue", "returns", "the", "previous", "value", "associated", "with", "the", "latest", "message", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/client/messages.go#L113-L123
4,833
ligato/cn-infra
messaging/kafka/client/messages.go
GetValue
func (pm *ProducerMessage) GetValue() []byte { val, _ := pm.Value.Encode() return val }
go
func (pm *ProducerMessage) GetValue() []byte { val, _ := pm.Value.Encode() return val }
[ "func", "(", "pm", "*", "ProducerMessage", ")", "GetValue", "(", ")", "[", "]", "byte", "{", "val", ",", "_", ":=", "pm", ".", "Value", ".", "Encode", "(", ")", "\n", "return", "val", "\n", "}" ]
// GetValue returns the content of the message.
[ "GetValue", "returns", "the", "content", "of", "the", "message", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/client/messages.go#L175-L178
4,834
ligato/cn-infra
messaging/kafka/client/messages.go
GetValue
func (ppm *ProtoProducerMessage) GetValue(msg proto.Message) error { err := ppm.Serializer.Unmarshal(ppm.ProducerMessage.GetValue(), msg) if err != nil { return err } return nil }
go
func (ppm *ProtoProducerMessage) GetValue(msg proto.Message) error { err := ppm.Serializer.Unmarshal(ppm.ProducerMessage.GetValue(), msg) if err != nil { return err } return nil }
[ "func", "(", "ppm", "*", "ProtoProducerMessage", ")", "GetValue", "(", "msg", "proto", ".", "Message", ")", "error", "{", "err", ":=", "ppm", ".", "Serializer", ".", "Unmarshal", "(", "ppm", ".", "ProducerMessage", ".", "GetValue", "(", ")", ",", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetValue unmarshalls the content of the msg into provided structure.
[ "GetValue", "unmarshalls", "the", "content", "of", "the", "msg", "into", "provided", "structure", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/client/messages.go#L255-L261
4,835
ligato/cn-infra
db/cryptodata/client.go
NewClient
func NewClient(clientConfig ClientConfig) *Client { client := &Client{ ClientConfig: clientConfig, } // If reader is nil use default rand.Reader if clientConfig.Reader == nil { client.Reader = rand.Reader } // If hash is nil use default sha256 if clientConfig.Hash == nil { client.Hash = sha256.New() } return client }
go
func NewClient(clientConfig ClientConfig) *Client { client := &Client{ ClientConfig: clientConfig, } // If reader is nil use default rand.Reader if clientConfig.Reader == nil { client.Reader = rand.Reader } // If hash is nil use default sha256 if clientConfig.Hash == nil { client.Hash = sha256.New() } return client }
[ "func", "NewClient", "(", "clientConfig", "ClientConfig", ")", "*", "Client", "{", "client", ":=", "&", "Client", "{", "ClientConfig", ":", "clientConfig", ",", "}", "\n\n", "// If reader is nil use default rand.Reader", "if", "clientConfig", ".", "Reader", "==", "nil", "{", "client", ".", "Reader", "=", "rand", ".", "Reader", "\n", "}", "\n\n", "// If hash is nil use default sha256", "if", "clientConfig", ".", "Hash", "==", "nil", "{", "client", ".", "Hash", "=", "sha256", ".", "New", "(", ")", "\n", "}", "\n\n", "return", "client", "\n", "}" ]
// NewClient creates new client from provided config and reader
[ "NewClient", "creates", "new", "client", "from", "provided", "config", "and", "reader" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/cryptodata/client.go#L55-L71
4,836
ligato/cn-infra
db/cryptodata/client.go
EncryptData
func (client *Client) EncryptData(inData []byte, pub *rsa.PublicKey) (data []byte, err error) { return rsa.EncryptOAEP(client.Hash, client.Reader, pub, inData, nil) }
go
func (client *Client) EncryptData(inData []byte, pub *rsa.PublicKey) (data []byte, err error) { return rsa.EncryptOAEP(client.Hash, client.Reader, pub, inData, nil) }
[ "func", "(", "client", "*", "Client", ")", "EncryptData", "(", "inData", "[", "]", "byte", ",", "pub", "*", "rsa", ".", "PublicKey", ")", "(", "data", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "rsa", ".", "EncryptOAEP", "(", "client", ".", "Hash", ",", "client", ".", "Reader", ",", "pub", ",", "inData", ",", "nil", ")", "\n", "}" ]
// EncryptData implements ClientAPI.EncryptData
[ "EncryptData", "implements", "ClientAPI", ".", "EncryptData" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/cryptodata/client.go#L74-L76
4,837
ligato/cn-infra
db/cryptodata/client.go
DecryptData
func (client *Client) DecryptData(inData []byte) (data []byte, err error) { for _, key := range client.PrivateKeys { data, err := rsa.DecryptOAEP(client.Hash, client.Reader, key, inData, nil) if err == nil { return data, nil } } return nil, errors.New("failed to decrypt data due to no private key matching") }
go
func (client *Client) DecryptData(inData []byte) (data []byte, err error) { for _, key := range client.PrivateKeys { data, err := rsa.DecryptOAEP(client.Hash, client.Reader, key, inData, nil) if err == nil { return data, nil } } return nil, errors.New("failed to decrypt data due to no private key matching") }
[ "func", "(", "client", "*", "Client", ")", "DecryptData", "(", "inData", "[", "]", "byte", ")", "(", "data", "[", "]", "byte", ",", "err", "error", ")", "{", "for", "_", ",", "key", ":=", "range", "client", ".", "PrivateKeys", "{", "data", ",", "err", ":=", "rsa", ".", "DecryptOAEP", "(", "client", ".", "Hash", ",", "client", ".", "Reader", ",", "key", ",", "inData", ",", "nil", ")", "\n\n", "if", "err", "==", "nil", "{", "return", "data", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// DecryptData implements ClientAPI.DecryptData
[ "DecryptData", "implements", "ClientAPI", ".", "DecryptData" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/cryptodata/client.go#L79-L89
4,838
ligato/cn-infra
db/cryptodata/client.go
WrapBytes
func (client *Client) WrapBytes(cbw keyval.KvBytesPlugin, decrypter ArbitraryDecrypter) keyval.KvBytesPlugin { return NewKvBytesPluginWrapper(cbw, decrypter, client.DecryptData) }
go
func (client *Client) WrapBytes(cbw keyval.KvBytesPlugin, decrypter ArbitraryDecrypter) keyval.KvBytesPlugin { return NewKvBytesPluginWrapper(cbw, decrypter, client.DecryptData) }
[ "func", "(", "client", "*", "Client", ")", "WrapBytes", "(", "cbw", "keyval", ".", "KvBytesPlugin", ",", "decrypter", "ArbitraryDecrypter", ")", "keyval", ".", "KvBytesPlugin", "{", "return", "NewKvBytesPluginWrapper", "(", "cbw", ",", "decrypter", ",", "client", ".", "DecryptData", ")", "\n", "}" ]
// WrapBytes implements ClientAPI.WrapBytes
[ "WrapBytes", "implements", "ClientAPI", ".", "WrapBytes" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/cryptodata/client.go#L92-L94
4,839
ligato/cn-infra
db/cryptodata/client.go
WrapProto
func (client *Client) WrapProto(kvp keyval.KvProtoPlugin, decrypter ArbitraryDecrypter) keyval.KvProtoPlugin { return NewKvProtoPluginWrapper(kvp, decrypter, client.DecryptData) }
go
func (client *Client) WrapProto(kvp keyval.KvProtoPlugin, decrypter ArbitraryDecrypter) keyval.KvProtoPlugin { return NewKvProtoPluginWrapper(kvp, decrypter, client.DecryptData) }
[ "func", "(", "client", "*", "Client", ")", "WrapProto", "(", "kvp", "keyval", ".", "KvProtoPlugin", ",", "decrypter", "ArbitraryDecrypter", ")", "keyval", ".", "KvProtoPlugin", "{", "return", "NewKvProtoPluginWrapper", "(", "kvp", ",", "decrypter", ",", "client", ".", "DecryptData", ")", "\n", "}" ]
// WrapProto implements ClientAPI.WrapProto
[ "WrapProto", "implements", "ClientAPI", ".", "WrapProto" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/cryptodata/client.go#L97-L99
4,840
ligato/cn-infra
datasync/kvdbsync/local/local_bytes_txn.go
NewBytesTxn
func NewBytesTxn(commit func(context.Context, map[string]datasync.ChangeValue) error) *BytesTxn { return &BytesTxn{ items: make(map[string]*bytesTxnItem), commit: commit, } }
go
func NewBytesTxn(commit func(context.Context, map[string]datasync.ChangeValue) error) *BytesTxn { return &BytesTxn{ items: make(map[string]*bytesTxnItem), commit: commit, } }
[ "func", "NewBytesTxn", "(", "commit", "func", "(", "context", ".", "Context", ",", "map", "[", "string", "]", "datasync", ".", "ChangeValue", ")", "error", ")", "*", "BytesTxn", "{", "return", "&", "BytesTxn", "{", "items", ":", "make", "(", "map", "[", "string", "]", "*", "bytesTxnItem", ")", ",", "commit", ":", "commit", ",", "}", "\n", "}" ]
// NewBytesTxn is a constructor.
[ "NewBytesTxn", "is", "a", "constructor", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/kvdbsync/local/local_bytes_txn.go#L41-L46
4,841
ligato/cn-infra
datasync/kvdbsync/local/local_bytes_txn.go
Delete
func (txn *BytesTxn) Delete(key string) keyval.BytesTxn { txn.access.Lock() defer txn.access.Unlock() txn.items[key] = &bytesTxnItem{delete: true} return txn }
go
func (txn *BytesTxn) Delete(key string) keyval.BytesTxn { txn.access.Lock() defer txn.access.Unlock() txn.items[key] = &bytesTxnItem{delete: true} return txn }
[ "func", "(", "txn", "*", "BytesTxn", ")", "Delete", "(", "key", "string", ")", "keyval", ".", "BytesTxn", "{", "txn", ".", "access", ".", "Lock", "(", ")", "\n", "defer", "txn", ".", "access", ".", "Unlock", "(", ")", "\n\n", "txn", ".", "items", "[", "key", "]", "=", "&", "bytesTxnItem", "{", "delete", ":", "true", "}", "\n\n", "return", "txn", "\n", "}" ]
// Delete add delete operation into transaction.
[ "Delete", "add", "delete", "operation", "into", "transaction", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/kvdbsync/local/local_bytes_txn.go#L59-L66
4,842
ligato/cn-infra
examples/bolt-plugin/main.go
Init
func (p *BoltExample) Init() (err error) { db := p.DB.NewBroker(keyval.Root) // Store some data txn := db.NewTxn() txn.Put("/agent/config/interface/iface0", nil) txn.Put("/agent/config/interface/iface1", nil) txn.Commit(context.Background()) // List keys const listPrefix = "/agent/config/interface/" p.Log.Infof("List BoltDB keys: %s", listPrefix) keys, err := db.ListKeys(listPrefix) if err != nil { p.Log.Fatal(err) } for { key, val, all := keys.GetNext() if all == true { break } p.Log.Infof("Key: %q Val: %v", key, val) } return nil }
go
func (p *BoltExample) Init() (err error) { db := p.DB.NewBroker(keyval.Root) // Store some data txn := db.NewTxn() txn.Put("/agent/config/interface/iface0", nil) txn.Put("/agent/config/interface/iface1", nil) txn.Commit(context.Background()) // List keys const listPrefix = "/agent/config/interface/" p.Log.Infof("List BoltDB keys: %s", listPrefix) keys, err := db.ListKeys(listPrefix) if err != nil { p.Log.Fatal(err) } for { key, val, all := keys.GetNext() if all == true { break } p.Log.Infof("Key: %q Val: %v", key, val) } return nil }
[ "func", "(", "p", "*", "BoltExample", ")", "Init", "(", ")", "(", "err", "error", ")", "{", "db", ":=", "p", ".", "DB", ".", "NewBroker", "(", "keyval", ".", "Root", ")", "\n\n", "// Store some data", "txn", ":=", "db", ".", "NewTxn", "(", ")", "\n", "txn", ".", "Put", "(", "\"", "\"", ",", "nil", ")", "\n", "txn", ".", "Put", "(", "\"", "\"", ",", "nil", ")", "\n", "txn", ".", "Commit", "(", "context", ".", "Background", "(", ")", ")", "\n\n", "// List keys", "const", "listPrefix", "=", "\"", "\"", "\n\n", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "listPrefix", ")", "\n\n", "keys", ",", "err", ":=", "db", ".", "ListKeys", "(", "listPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "for", "{", "key", ",", "val", ",", "all", ":=", "keys", ".", "GetNext", "(", ")", "\n", "if", "all", "==", "true", "{", "break", "\n", "}", "\n\n", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "key", ",", "val", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Init demonstrates using Bolt plugin.
[ "Init", "demonstrates", "using", "Bolt", "plugin", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/bolt-plugin/main.go#L40-L69
4,843
ligato/cn-infra
db/keyval/etcd/mocks/embeded_etcd.go
Start
func (embd *Embedded) Start(t *testing.T) { dir, err := ioutil.TempDir("", "ETCD") if err != nil { t.Error(err) t.FailNow() } cfg := embed.NewConfig() cfg.Dir = dir lpurl, _ := url.Parse("http://localhost:0") lcurl, _ := url.Parse("http://localhost:0") cfg.LPUrls = []url.URL{*lpurl} cfg.LCUrls = []url.URL{*lcurl} embd.ETCD, err = embed.StartEtcd(cfg) if err != nil { t.Error(err) t.FailNow() } select { case <-embd.ETCD.Server.ReadyNotify(): logrus.DefaultLogger().Debug("Server is ready!") case <-time.After(etcdStartTimeout * time.Second): embd.ETCD.Server.Stop() // trigger a shutdown t.Error("Server took too long to start!") t.FailNow() } embd.client = v3client.New(embd.ETCD.Server) }
go
func (embd *Embedded) Start(t *testing.T) { dir, err := ioutil.TempDir("", "ETCD") if err != nil { t.Error(err) t.FailNow() } cfg := embed.NewConfig() cfg.Dir = dir lpurl, _ := url.Parse("http://localhost:0") lcurl, _ := url.Parse("http://localhost:0") cfg.LPUrls = []url.URL{*lpurl} cfg.LCUrls = []url.URL{*lcurl} embd.ETCD, err = embed.StartEtcd(cfg) if err != nil { t.Error(err) t.FailNow() } select { case <-embd.ETCD.Server.ReadyNotify(): logrus.DefaultLogger().Debug("Server is ready!") case <-time.After(etcdStartTimeout * time.Second): embd.ETCD.Server.Stop() // trigger a shutdown t.Error("Server took too long to start!") t.FailNow() } embd.client = v3client.New(embd.ETCD.Server) }
[ "func", "(", "embd", "*", "Embedded", ")", "Start", "(", "t", "*", "testing", ".", "T", ")", "{", "dir", ",", "err", ":=", "ioutil", ".", "TempDir", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "t", ".", "Error", "(", "err", ")", "\n", "t", ".", "FailNow", "(", ")", "\n", "}", "\n\n", "cfg", ":=", "embed", ".", "NewConfig", "(", ")", "\n", "cfg", ".", "Dir", "=", "dir", "\n", "lpurl", ",", "_", ":=", "url", ".", "Parse", "(", "\"", "\"", ")", "\n", "lcurl", ",", "_", ":=", "url", ".", "Parse", "(", "\"", "\"", ")", "\n", "cfg", ".", "LPUrls", "=", "[", "]", "url", ".", "URL", "{", "*", "lpurl", "}", "\n", "cfg", ".", "LCUrls", "=", "[", "]", "url", ".", "URL", "{", "*", "lcurl", "}", "\n", "embd", ".", "ETCD", ",", "err", "=", "embed", ".", "StartEtcd", "(", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "t", ".", "Error", "(", "err", ")", "\n", "t", ".", "FailNow", "(", ")", "\n\n", "}", "\n\n", "select", "{", "case", "<-", "embd", ".", "ETCD", ".", "Server", ".", "ReadyNotify", "(", ")", ":", "logrus", ".", "DefaultLogger", "(", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "case", "<-", "time", ".", "After", "(", "etcdStartTimeout", "*", "time", ".", "Second", ")", ":", "embd", ".", "ETCD", ".", "Server", ".", "Stop", "(", ")", "// trigger a shutdown", "\n", "t", ".", "Error", "(", "\"", "\"", ")", "\n", "t", ".", "FailNow", "(", ")", "\n", "}", "\n", "embd", ".", "client", "=", "v3client", ".", "New", "(", "embd", ".", "ETCD", ".", "Server", ")", "\n", "}" ]
// Start starts embedded ETCD.
[ "Start", "starts", "embedded", "ETCD", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/etcd/mocks/embeded_etcd.go#L28-L57
4,844
ligato/cn-infra
db/keyval/etcd/mocks/embeded_etcd.go
Stop
func (embd *Embedded) Stop() { embd.ETCD.Close() os.RemoveAll(embd.tmpDir) }
go
func (embd *Embedded) Stop() { embd.ETCD.Close() os.RemoveAll(embd.tmpDir) }
[ "func", "(", "embd", "*", "Embedded", ")", "Stop", "(", ")", "{", "embd", ".", "ETCD", ".", "Close", "(", ")", "\n", "os", ".", "RemoveAll", "(", "embd", ".", "tmpDir", ")", "\n", "}" ]
// Stop stops the embedded ETCD & cleanups the tmp dir.
[ "Stop", "stops", "the", "embedded", "ETCD", "&", "cleanups", "the", "tmp", "dir", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/etcd/mocks/embeded_etcd.go#L60-L63
4,845
ligato/cn-infra
db/keyval/etcd/mocks/embeded_etcd.go
CleanDs
func (embd *Embedded) CleanDs() { if embd.client != nil { resp, err := embd.client.Delete(context.Background(), "", clientv3.WithPrefix()) if err != nil { panic(err) } fmt.Printf("resp: %+v\n", resp) } }
go
func (embd *Embedded) CleanDs() { if embd.client != nil { resp, err := embd.client.Delete(context.Background(), "", clientv3.WithPrefix()) if err != nil { panic(err) } fmt.Printf("resp: %+v\n", resp) } }
[ "func", "(", "embd", "*", "Embedded", ")", "CleanDs", "(", ")", "{", "if", "embd", ".", "client", "!=", "nil", "{", "resp", ",", "err", ":=", "embd", ".", "client", ".", "Delete", "(", "context", ".", "Background", "(", ")", ",", "\"", "\"", ",", "clientv3", ".", "WithPrefix", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "resp", ")", "\n", "}", "\n", "}" ]
// CleanDs deletes all stored key-value pairs.
[ "CleanDs", "deletes", "all", "stored", "key", "-", "value", "pairs", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/etcd/mocks/embeded_etcd.go#L66-L74
4,846
ligato/cn-infra
datasync/restsync/rest_watcher.go
NewAdapter
func NewAdapter(registerHTTPHandler registerHTTPHandler, localtransp *syncbase.Registry) *Adapter { return &Adapter{registerHTTPHandler: registerHTTPHandler, base: localtransp} }
go
func NewAdapter(registerHTTPHandler registerHTTPHandler, localtransp *syncbase.Registry) *Adapter { return &Adapter{registerHTTPHandler: registerHTTPHandler, base: localtransp} }
[ "func", "NewAdapter", "(", "registerHTTPHandler", "registerHTTPHandler", ",", "localtransp", "*", "syncbase", ".", "Registry", ")", "*", "Adapter", "{", "return", "&", "Adapter", "{", "registerHTTPHandler", ":", "registerHTTPHandler", ",", "base", ":", "localtransp", "}", "\n", "}" ]
// NewAdapter is a constructor.
[ "NewAdapter", "is", "a", "constructor", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/restsync/rest_watcher.go#L33-L35
4,847
ligato/cn-infra
datasync/restsync/rest_watcher.go
Watch
func (adapter *Adapter) Watch(resyncName string, changeChan chan datasync.ChangeEvent, resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error) { logrus.DefaultLogger().Debug("REST KeyValProtoWatcher WatchData ", resyncName, " ", keyPrefixes) for _, keyPrefix := range keyPrefixes { adapter.registerHTTPHandler(keyPrefix+"{suffix}", adapter.putMessage, "PUT") adapter.registerHTTPHandler(keyPrefix+"{suffix}", adapter.delMessage, "DELETE") //TODO adapter.registerHTTPHandler(keyPrefix + "{suffix}", getMessage, "GET") //TODO httpmux.RegisterHTTPHandler("/vpprestcon/resync", putResync, "PUT") } return adapter.base.Watch(resyncName, changeChan, resyncChan, keyPrefixes...) }
go
func (adapter *Adapter) Watch(resyncName string, changeChan chan datasync.ChangeEvent, resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error) { logrus.DefaultLogger().Debug("REST KeyValProtoWatcher WatchData ", resyncName, " ", keyPrefixes) for _, keyPrefix := range keyPrefixes { adapter.registerHTTPHandler(keyPrefix+"{suffix}", adapter.putMessage, "PUT") adapter.registerHTTPHandler(keyPrefix+"{suffix}", adapter.delMessage, "DELETE") //TODO adapter.registerHTTPHandler(keyPrefix + "{suffix}", getMessage, "GET") //TODO httpmux.RegisterHTTPHandler("/vpprestcon/resync", putResync, "PUT") } return adapter.base.Watch(resyncName, changeChan, resyncChan, keyPrefixes...) }
[ "func", "(", "adapter", "*", "Adapter", ")", "Watch", "(", "resyncName", "string", ",", "changeChan", "chan", "datasync", ".", "ChangeEvent", ",", "resyncChan", "chan", "datasync", ".", "ResyncEvent", ",", "keyPrefixes", "...", "string", ")", "(", "datasync", ".", "WatchRegistration", ",", "error", ")", "{", "logrus", ".", "DefaultLogger", "(", ")", ".", "Debug", "(", "\"", "\"", ",", "resyncName", ",", "\"", "\"", ",", "keyPrefixes", ")", "\n\n", "for", "_", ",", "keyPrefix", ":=", "range", "keyPrefixes", "{", "adapter", ".", "registerHTTPHandler", "(", "keyPrefix", "+", "\"", "\"", ",", "adapter", ".", "putMessage", ",", "\"", "\"", ")", "\n", "adapter", ".", "registerHTTPHandler", "(", "keyPrefix", "+", "\"", "\"", ",", "adapter", ".", "delMessage", ",", "\"", "\"", ")", "\n", "//TODO adapter.registerHTTPHandler(keyPrefix + \"{suffix}\", getMessage, \"GET\")", "//TODO httpmux.RegisterHTTPHandler(\"/vpprestcon/resync\", putResync, \"PUT\")", "}", "\n\n", "return", "adapter", ".", "base", ".", "Watch", "(", "resyncName", ",", "changeChan", ",", "resyncChan", ",", "keyPrefixes", "...", ")", "\n", "}" ]
// Watch registers HTTP handlers - basically bridges them with local dbadapter.
[ "Watch", "registers", "HTTP", "handlers", "-", "basically", "bridges", "them", "with", "local", "dbadapter", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/restsync/rest_watcher.go#L50-L63
4,848
ligato/cn-infra
examples/kafka-lib/consumer/consumer.go
watchChannels
func watchChannels(consumer *client.Consumer, cfg *client.Config) { for { select { case notification, more := <-cfg.RecvNotificationChan: if more { handleNotifcation(consumer, notification) } case err, more := <-cfg.RecvErrorChan: if more { fmt.Printf("Message Recv Errored: %v\n", err) } case msg, more := <-cfg.RecvMessageChan: if more { messageCallback(consumer, msg, *commit) } case <-consumer.GetCloseChannel(): return } } }
go
func watchChannels(consumer *client.Consumer, cfg *client.Config) { for { select { case notification, more := <-cfg.RecvNotificationChan: if more { handleNotifcation(consumer, notification) } case err, more := <-cfg.RecvErrorChan: if more { fmt.Printf("Message Recv Errored: %v\n", err) } case msg, more := <-cfg.RecvMessageChan: if more { messageCallback(consumer, msg, *commit) } case <-consumer.GetCloseChannel(): return } } }
[ "func", "watchChannels", "(", "consumer", "*", "client", ".", "Consumer", ",", "cfg", "*", "client", ".", "Config", ")", "{", "for", "{", "select", "{", "case", "notification", ",", "more", ":=", "<-", "cfg", ".", "RecvNotificationChan", ":", "if", "more", "{", "handleNotifcation", "(", "consumer", ",", "notification", ")", "\n", "}", "\n", "case", "err", ",", "more", ":=", "<-", "cfg", ".", "RecvErrorChan", ":", "if", "more", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "err", ")", "\n", "}", "\n", "case", "msg", ",", "more", ":=", "<-", "cfg", ".", "RecvMessageChan", ":", "if", "more", "{", "messageCallback", "(", "consumer", ",", "msg", ",", "*", "commit", ")", "\n", "}", "\n", "case", "<-", "consumer", ".", "GetCloseChannel", "(", ")", ":", "return", "\n", "}", "\n", "}", "\n", "}" ]
// watchChannels watches channels configured for delivery of Kafka messages, // notifications and errors.
[ "watchChannels", "watches", "channels", "configured", "for", "delivery", "of", "Kafka", "messages", "notifications", "and", "errors", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/kafka-lib/consumer/consumer.go#L134-L154
4,849
ligato/cn-infra
examples/prometheus-plugin/main.go
Init
func (plugin *ExamplePlugin) Init() error { // add new metric to default registry (accessible at the path /metrics) // // the current value is returned by provided callback // created gauge is identified by tuple(namespace, subsystem, name) only the name field is mandatory // additional properties can be defined using labels - key-value pairs. They do not change over time for the given gauge. err := plugin.Prometheus.RegisterGaugeFunc(prom.DefaultRegistry, "ns", "sub", "gaugeOne", "this metrics represents randomly generated numbers", prometheus.Labels{"Property1": "ABC", "Property2": "DEF"}, func() float64 { return rand.Float64() }) if err != nil { return err } // create new registry that will be exposed at /custom path err = plugin.Prometheus.NewRegistry(customRegistry, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}) if err != nil { return err } // create gauge using prometheus API plugin.temporaryCounter = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "Countdown", Help: "This gauge is decremented by 1 each second, once it reaches 0 the gauge is removed.", }) plugin.counterVal = 60 plugin.temporaryCounter.Set(float64(plugin.counterVal)) // register created gauge to the custom registry err = plugin.Prometheus.Register(customRegistry, plugin.temporaryCounter) if err != nil { return err } // create gauge vector and register it plugin.gaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "Vector", Help: "This gauge groups multiple similar metrics.", ConstLabels: prometheus.Labels{"type": "vector", "answer": "42"}, }, []string{orderLabel}) err = plugin.Prometheus.Register(customRegistry, plugin.gaugeVec) return err }
go
func (plugin *ExamplePlugin) Init() error { // add new metric to default registry (accessible at the path /metrics) // // the current value is returned by provided callback // created gauge is identified by tuple(namespace, subsystem, name) only the name field is mandatory // additional properties can be defined using labels - key-value pairs. They do not change over time for the given gauge. err := plugin.Prometheus.RegisterGaugeFunc(prom.DefaultRegistry, "ns", "sub", "gaugeOne", "this metrics represents randomly generated numbers", prometheus.Labels{"Property1": "ABC", "Property2": "DEF"}, func() float64 { return rand.Float64() }) if err != nil { return err } // create new registry that will be exposed at /custom path err = plugin.Prometheus.NewRegistry(customRegistry, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}) if err != nil { return err } // create gauge using prometheus API plugin.temporaryCounter = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "Countdown", Help: "This gauge is decremented by 1 each second, once it reaches 0 the gauge is removed.", }) plugin.counterVal = 60 plugin.temporaryCounter.Set(float64(plugin.counterVal)) // register created gauge to the custom registry err = plugin.Prometheus.Register(customRegistry, plugin.temporaryCounter) if err != nil { return err } // create gauge vector and register it plugin.gaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "Vector", Help: "This gauge groups multiple similar metrics.", ConstLabels: prometheus.Labels{"type": "vector", "answer": "42"}, }, []string{orderLabel}) err = plugin.Prometheus.Register(customRegistry, plugin.gaugeVec) return err }
[ "func", "(", "plugin", "*", "ExamplePlugin", ")", "Init", "(", ")", "error", "{", "// add new metric to default registry (accessible at the path /metrics)", "//", "// the current value is returned by provided callback", "// created gauge is identified by tuple(namespace, subsystem, name) only the name field is mandatory", "// additional properties can be defined using labels - key-value pairs. They do not change over time for the given gauge.", "err", ":=", "plugin", ".", "Prometheus", ".", "RegisterGaugeFunc", "(", "prom", ".", "DefaultRegistry", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "prometheus", ".", "Labels", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", "}", ",", "func", "(", ")", "float64", "{", "return", "rand", ".", "Float64", "(", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// create new registry that will be exposed at /custom path", "err", "=", "plugin", ".", "Prometheus", ".", "NewRegistry", "(", "customRegistry", ",", "promhttp", ".", "HandlerOpts", "{", "ErrorHandling", ":", "promhttp", ".", "ContinueOnError", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// create gauge using prometheus API", "plugin", ".", "temporaryCounter", "=", "prometheus", ".", "NewGauge", "(", "prometheus", ".", "GaugeOpts", "{", "Name", ":", "\"", "\"", ",", "Help", ":", "\"", "\"", ",", "}", ")", "\n", "plugin", ".", "counterVal", "=", "60", "\n", "plugin", ".", "temporaryCounter", ".", "Set", "(", "float64", "(", "plugin", ".", "counterVal", ")", ")", "\n\n", "// register created gauge to the custom registry", "err", "=", "plugin", ".", "Prometheus", ".", "Register", "(", "customRegistry", ",", "plugin", ".", "temporaryCounter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// create gauge vector and register it", "plugin", ".", "gaugeVec", "=", "prometheus", ".", "NewGaugeVec", "(", "prometheus", ".", "GaugeOpts", "{", "Name", ":", "\"", "\"", ",", "Help", ":", "\"", "\"", ",", "ConstLabels", ":", "prometheus", ".", "Labels", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", "}", ",", "}", ",", "[", "]", "string", "{", "orderLabel", "}", ")", "\n", "err", "=", "plugin", ".", "Prometheus", ".", "Register", "(", "customRegistry", ",", "plugin", ".", "gaugeVec", ")", "\n\n", "return", "err", "\n\n", "}" ]
// Init creates metric registries and adds gauges
[ "Init", "creates", "metric", "registries", "and", "adds", "gauges" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/prometheus-plugin/main.go#L72-L117
4,850
ligato/cn-infra
processmanager/process_options.go
Writer
func Writer(outW, errW io.Writer) POption { return func(p *POptions) { p.outWriter, p.errWriter = outW, errW } }
go
func Writer(outW, errW io.Writer) POption { return func(p *POptions) { p.outWriter, p.errWriter = outW, errW } }
[ "func", "Writer", "(", "outW", ",", "errW", "io", ".", "Writer", ")", "POption", "{", "return", "func", "(", "p", "*", "POptions", ")", "{", "p", ".", "outWriter", ",", "p", ".", "errWriter", "=", "outW", ",", "errW", "\n", "}", "\n", "}" ]
// Writer allows to use custom writer instance. Can be defined with nil parameters, in such a case // standard output will be used
[ "Writer", "allows", "to", "use", "custom", "writer", "instance", ".", "Can", "be", "defined", "with", "nil", "parameters", "in", "such", "a", "case", "standard", "output", "will", "be", "used" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/process_options.go#L71-L75
4,851
ligato/cn-infra
processmanager/process_options.go
Template
func Template(runOnStartup bool) POption { return func(p *POptions) { p.template = true p.runOnStartup = runOnStartup } }
go
func Template(runOnStartup bool) POption { return func(p *POptions) { p.template = true p.runOnStartup = runOnStartup } }
[ "func", "Template", "(", "runOnStartup", "bool", ")", "POption", "{", "return", "func", "(", "p", "*", "POptions", ")", "{", "p", ".", "template", "=", "true", "\n", "p", ".", "runOnStartup", "=", "runOnStartup", "\n", "}", "\n", "}" ]
// Template will be created for given process. Process template also requires a flag whether the process // should be started automatically with plugin
[ "Template", "will", "be", "created", "for", "given", "process", ".", "Process", "template", "also", "requires", "a", "flag", "whether", "the", "process", "should", "be", "started", "automatically", "with", "plugin" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/process_options.go#L93-L98
4,852
paked/configure
hcl.go
Setup
func (h *HCL) Setup() error { r, err := h.gen() if err != nil { return err } buf := new(bytes.Buffer) buf.ReadFrom(r) s := buf.String() //first parse the hcl file obj, err := hcl.Parse(s) if err != nil { return err } h.values = make(map[string]interface{}) // then decode the object if err = hcl.DecodeObject(&h.values, obj); err != nil { return err } return nil }
go
func (h *HCL) Setup() error { r, err := h.gen() if err != nil { return err } buf := new(bytes.Buffer) buf.ReadFrom(r) s := buf.String() //first parse the hcl file obj, err := hcl.Parse(s) if err != nil { return err } h.values = make(map[string]interface{}) // then decode the object if err = hcl.DecodeObject(&h.values, obj); err != nil { return err } return nil }
[ "func", "(", "h", "*", "HCL", ")", "Setup", "(", ")", "error", "{", "r", ",", "err", ":=", "h", ".", "gen", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "buf", ".", "ReadFrom", "(", "r", ")", "\n", "s", ":=", "buf", ".", "String", "(", ")", "\n\n", "//first parse the hcl file", "obj", ",", "err", ":=", "hcl", ".", "Parse", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "h", ".", "values", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "// then decode the object", "if", "err", "=", "hcl", ".", "DecodeObject", "(", "&", "h", ".", "values", ",", "obj", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Setup initializes the HCL Checker
[ "Setup", "initializes", "the", "HCL", "Checker" ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/hcl.go#L38-L62
4,853
paked/configure
hcl.go
Int
func (h *HCL) Int(name string) (int, error) { v, err := h.value(name) if err != nil { return 0, err } f, ok := v.(float64) if !ok { i, ok := v.(int) if !ok { return v.(int), errors.New(fmt.Sprintf("%T unable", v)) } return i, nil } return int(f), nil }
go
func (h *HCL) Int(name string) (int, error) { v, err := h.value(name) if err != nil { return 0, err } f, ok := v.(float64) if !ok { i, ok := v.(int) if !ok { return v.(int), errors.New(fmt.Sprintf("%T unable", v)) } return i, nil } return int(f), nil }
[ "func", "(", "h", "*", "HCL", ")", "Int", "(", "name", "string", ")", "(", "int", ",", "error", ")", "{", "v", ",", "err", ":=", "h", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "f", ",", "ok", ":=", "v", ".", "(", "float64", ")", "\n", "if", "!", "ok", "{", "i", ",", "ok", ":=", "v", ".", "(", "int", ")", "\n", "if", "!", "ok", "{", "return", "v", ".", "(", "int", ")", ",", "errors", ".", "New", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ")", ")", "\n", "}", "\n\n", "return", "i", ",", "nil", "\n", "}", "\n\n", "return", "int", "(", "f", ")", ",", "nil", "\n", "}" ]
// Int returns an int if it exists within the HCL io.Reader
[ "Int", "returns", "an", "int", "if", "it", "exists", "within", "the", "HCL", "io", ".", "Reader" ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/hcl.go#L74-L91
4,854
paked/configure
hcl.go
Bool
func (h *HCL) Bool(name string) (bool, error) { v, err := h.value(name) if err != nil { return false, err } return v.(bool), nil }
go
func (h *HCL) Bool(name string) (bool, error) { v, err := h.value(name) if err != nil { return false, err } return v.(bool), nil }
[ "func", "(", "h", "*", "HCL", ")", "Bool", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "v", ",", "err", ":=", "h", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "v", ".", "(", "bool", ")", ",", "nil", "\n", "}" ]
// Bool returns a bool if it exists within the HCL io.Reader.
[ "Bool", "returns", "a", "bool", "if", "it", "exists", "within", "the", "HCL", "io", ".", "Reader", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/hcl.go#L94-L101
4,855
paked/configure
hcl.go
String
func (h *HCL) String(name string) (string, error) { v, err := h.value(name) if err != nil { return "", err } return v.(string), nil }
go
func (h *HCL) String(name string) (string, error) { v, err := h.value(name) if err != nil { return "", err } return v.(string), nil }
[ "func", "(", "h", "*", "HCL", ")", "String", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "v", ",", "err", ":=", "h", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "v", ".", "(", "string", ")", ",", "nil", "\n", "}" ]
// String returns a string if it exists within the HCL io.Reader.
[ "String", "returns", "a", "string", "if", "it", "exists", "within", "the", "HCL", "io", ".", "Reader", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/hcl.go#L104-L111
4,856
paked/configure
configure.go
Int
func (c *Configure) Int(name string, def int, description string) *int { i := new(int) c.IntVar(i, name, def, description) return i }
go
func (c *Configure) Int(name string, def int, description string) *int { i := new(int) c.IntVar(i, name, def, description) return i }
[ "func", "(", "c", "*", "Configure", ")", "Int", "(", "name", "string", ",", "def", "int", ",", "description", "string", ")", "*", "int", "{", "i", ":=", "new", "(", "int", ")", "\n", "c", ".", "IntVar", "(", "i", ",", "name", ",", "def", ",", "description", ")", "\n\n", "return", "i", "\n", "}" ]
// Int defines an int flag with a name, default and description. The return value // is a pointer which will be populated with the value of the flag.
[ "Int", "defines", "an", "int", "flag", "with", "a", "name", "default", "and", "description", ".", "The", "return", "value", "is", "a", "pointer", "which", "will", "be", "populated", "with", "the", "value", "of", "the", "flag", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L38-L43
4,857
paked/configure
configure.go
String
func (c *Configure) String(name string, def string, description string) *string { s := new(string) c.StringVar(s, name, def, description) return s }
go
func (c *Configure) String(name string, def string, description string) *string { s := new(string) c.StringVar(s, name, def, description) return s }
[ "func", "(", "c", "*", "Configure", ")", "String", "(", "name", "string", ",", "def", "string", ",", "description", "string", ")", "*", "string", "{", "s", ":=", "new", "(", "string", ")", "\n", "c", ".", "StringVar", "(", "s", ",", "name", ",", "def", ",", "description", ")", "\n\n", "return", "s", "\n", "}" ]
// String defines a string flag with a name, default and description. The return value // is a pointer which will be populated with the value of the flag.
[ "String", "defines", "a", "string", "flag", "with", "a", "name", "default", "and", "description", ".", "The", "return", "value", "is", "a", "pointer", "which", "will", "be", "populated", "with", "the", "value", "of", "the", "flag", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L52-L57
4,858
paked/configure
configure.go
Bool
func (c *Configure) Bool(name string, def bool, description string) *bool { b := new(bool) c.BoolVar(b, name, def, description) return b }
go
func (c *Configure) Bool(name string, def bool, description string) *bool { b := new(bool) c.BoolVar(b, name, def, description) return b }
[ "func", "(", "c", "*", "Configure", ")", "Bool", "(", "name", "string", ",", "def", "bool", ",", "description", "string", ")", "*", "bool", "{", "b", ":=", "new", "(", "bool", ")", "\n", "c", ".", "BoolVar", "(", "b", ",", "name", ",", "def", ",", "description", ")", "\n\n", "return", "b", "\n", "}" ]
// Bool defines a bool flag with a name, default and description. The return value // is a pointer which will be populated with the value of the flag.
[ "Bool", "defines", "a", "bool", "flag", "with", "a", "name", "default", "and", "description", ".", "The", "return", "value", "is", "a", "pointer", "which", "will", "be", "populated", "with", "the", "value", "of", "the", "flag", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L66-L71
4,859
paked/configure
configure.go
option
func (c *Configure) option(value interface{}, name string, def interface{}, description string, typ valueType) { opt := &option{ name: name, def: def, description: description, typ: typ, value: value, } c.options[name] = opt }
go
func (c *Configure) option(value interface{}, name string, def interface{}, description string, typ valueType) { opt := &option{ name: name, def: def, description: description, typ: typ, value: value, } c.options[name] = opt }
[ "func", "(", "c", "*", "Configure", ")", "option", "(", "value", "interface", "{", "}", ",", "name", "string", ",", "def", "interface", "{", "}", ",", "description", "string", ",", "typ", "valueType", ")", "{", "opt", ":=", "&", "option", "{", "name", ":", "name", ",", "def", ":", "def", ",", "description", ":", "description", ",", "typ", ":", "typ", ",", "value", ":", "value", ",", "}", "\n\n", "c", ".", "options", "[", "name", "]", "=", "opt", "\n", "}" ]
// option will bind a pointer to a value provided in the value parameter to // set flag value.
[ "option", "will", "bind", "a", "pointer", "to", "a", "value", "provided", "in", "the", "value", "parameter", "to", "set", "flag", "value", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L75-L85
4,860
paked/configure
configure.go
Use
func (c *Configure) Use(checkers ...Checker) { c.stack = append(c.stack, checkers...) }
go
func (c *Configure) Use(checkers ...Checker) { c.stack = append(c.stack, checkers...) }
[ "func", "(", "c", "*", "Configure", ")", "Use", "(", "checkers", "...", "Checker", ")", "{", "c", ".", "stack", "=", "append", "(", "c", ".", "stack", ",", "checkers", "...", ")", "\n", "}" ]
// Use adds a variable amount of Checkers onto the stack.
[ "Use", "adds", "a", "variable", "amount", "of", "Checkers", "onto", "the", "stack", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L88-L90
4,861
paked/configure
configure.go
Parse
func (c *Configure) Parse() { c.setup() for _, opt := range c.options { changed := false for _, checker := range c.stack { switch opt.typ { case stringType: s, err := checker.String(opt.name) if err != nil { continue } opt.set(s) case intType: i, err := checker.Int(opt.name) if err != nil { continue } opt.set(i) case boolType: b, err := checker.Bool(opt.name) if err != nil { continue } opt.set(b) } changed = true break } if !changed { opt.set(opt.def) } } }
go
func (c *Configure) Parse() { c.setup() for _, opt := range c.options { changed := false for _, checker := range c.stack { switch opt.typ { case stringType: s, err := checker.String(opt.name) if err != nil { continue } opt.set(s) case intType: i, err := checker.Int(opt.name) if err != nil { continue } opt.set(i) case boolType: b, err := checker.Bool(opt.name) if err != nil { continue } opt.set(b) } changed = true break } if !changed { opt.set(opt.def) } } }
[ "func", "(", "c", "*", "Configure", ")", "Parse", "(", ")", "{", "c", ".", "setup", "(", ")", "\n", "for", "_", ",", "opt", ":=", "range", "c", ".", "options", "{", "changed", ":=", "false", "\n", "for", "_", ",", "checker", ":=", "range", "c", ".", "stack", "{", "switch", "opt", ".", "typ", "{", "case", "stringType", ":", "s", ",", "err", ":=", "checker", ".", "String", "(", "opt", ".", "name", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "opt", ".", "set", "(", "s", ")", "\n", "case", "intType", ":", "i", ",", "err", ":=", "checker", ".", "Int", "(", "opt", ".", "name", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "opt", ".", "set", "(", "i", ")", "\n", "case", "boolType", ":", "b", ",", "err", ":=", "checker", ".", "Bool", "(", "opt", ".", "name", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "opt", ".", "set", "(", "b", ")", "\n", "}", "\n\n", "changed", "=", "true", "\n", "break", "\n", "}", "\n\n", "if", "!", "changed", "{", "opt", ".", "set", "(", "opt", ".", "def", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Parse populates all of the defined arguments with their values provided by // the stacks Checkers.
[ "Parse", "populates", "all", "of", "the", "defined", "arguments", "with", "their", "values", "provided", "by", "the", "stacks", "Checkers", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L104-L141
4,862
paked/configure
configure.go
New
func New(stack ...Checker) *Configure { c := &Configure{ options: make(map[string]*option), stack: stack, } return c }
go
func New(stack ...Checker) *Configure { c := &Configure{ options: make(map[string]*option), stack: stack, } return c }
[ "func", "New", "(", "stack", "...", "Checker", ")", "*", "Configure", "{", "c", ":=", "&", "Configure", "{", "options", ":", "make", "(", "map", "[", "string", "]", "*", "option", ")", ",", "stack", ":", "stack", ",", "}", "\n\n", "return", "c", "\n", "}" ]
// New returns a pointer to a new Configure instance with a stack // provided through the variadic stack variable.
[ "New", "returns", "a", "pointer", "to", "a", "new", "Configure", "instance", "with", "a", "stack", "provided", "through", "the", "variadic", "stack", "variable", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/configure.go#L145-L152
4,863
paked/configure
environment.go
Int
func (e Environment) Int(name string) (int, error) { v, err := e.value(name) if err != nil { return 0, err } i, err := strconv.Atoi(v) if err != nil { return 0, err } return i, nil }
go
func (e Environment) Int(name string) (int, error) { v, err := e.value(name) if err != nil { return 0, err } i, err := strconv.Atoi(v) if err != nil { return 0, err } return i, nil }
[ "func", "(", "e", "Environment", ")", "Int", "(", "name", "string", ")", "(", "int", ",", "error", ")", "{", "v", ",", "err", ":=", "e", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "i", ",", "err", ":=", "strconv", ".", "Atoi", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "i", ",", "nil", "\n", "}" ]
// Int returns an int if it exists in the set environment variables.
[ "Int", "returns", "an", "int", "if", "it", "exists", "in", "the", "set", "environment", "variables", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/environment.go#L49-L61
4,864
paked/configure
environment.go
Bool
func (e *Environment) Bool(name string) (bool, error) { v, err := e.value(name) if err != nil { return false, err } return strconv.ParseBool(v) }
go
func (e *Environment) Bool(name string) (bool, error) { v, err := e.value(name) if err != nil { return false, err } return strconv.ParseBool(v) }
[ "func", "(", "e", "*", "Environment", ")", "Bool", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "v", ",", "err", ":=", "e", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "strconv", ".", "ParseBool", "(", "v", ")", "\n", "}" ]
// Bool returns a bool if it exists in the set environment variables.
[ "Bool", "returns", "a", "bool", "if", "it", "exists", "in", "the", "set", "environment", "variables", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/environment.go#L64-L71
4,865
paked/configure
environment.go
String
func (e Environment) String(name string) (string, error) { return e.value(name) }
go
func (e Environment) String(name string) (string, error) { return e.value(name) }
[ "func", "(", "e", "Environment", ")", "String", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "return", "e", ".", "value", "(", "name", ")", "\n", "}" ]
// String returns a string if it exists in the set environment variables.
[ "String", "returns", "a", "string", "if", "it", "exists", "in", "the", "set", "environment", "variables", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/environment.go#L74-L76
4,866
paked/configure
json.go
NewJSONFromFile
func NewJSONFromFile(path string) *JSON { return NewJSON(func() (io.Reader, error) { return os.Open(path) }) }
go
func NewJSONFromFile(path string) *JSON { return NewJSON(func() (io.Reader, error) { return os.Open(path) }) }
[ "func", "NewJSONFromFile", "(", "path", "string", ")", "*", "JSON", "{", "return", "NewJSON", "(", "func", "(", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "return", "os", ".", "Open", "(", "path", ")", "\n", "}", ")", "\n", "}" ]
// NewJSONFromFile returns an instance of the JSON checker. It reads its // data from a file which its location has been specified through the path // parameter
[ "NewJSONFromFile", "returns", "an", "instance", "of", "the", "JSON", "checker", ".", "It", "reads", "its", "data", "from", "a", "file", "which", "its", "location", "has", "been", "specified", "through", "the", "path", "parameter" ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/json.go#L23-L27
4,867
paked/configure
json.go
Setup
func (j *JSON) Setup() error { r, err := j.gen() if err != nil { return err } dec := json.NewDecoder(r) j.values = make(map[string]interface{}) return dec.Decode(&j.values) }
go
func (j *JSON) Setup() error { r, err := j.gen() if err != nil { return err } dec := json.NewDecoder(r) j.values = make(map[string]interface{}) return dec.Decode(&j.values) }
[ "func", "(", "j", "*", "JSON", ")", "Setup", "(", ")", "error", "{", "r", ",", "err", ":=", "j", ".", "gen", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "dec", ":=", "json", ".", "NewDecoder", "(", "r", ")", "\n", "j", ".", "values", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "return", "dec", ".", "Decode", "(", "&", "j", ".", "values", ")", "\n", "}" ]
//Setup initializes the JSON Checker
[ "Setup", "initializes", "the", "JSON", "Checker" ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/json.go#L36-L46
4,868
paked/configure
json.go
Int
func (j *JSON) Int(name string) (int, error) { v, err := j.value(name) if err != nil { return 0, err } f, ok := v.(float64) if !ok { return 0, errors.New(fmt.Sprintf("%T unable", v)) } return int(f), nil }
go
func (j *JSON) Int(name string) (int, error) { v, err := j.value(name) if err != nil { return 0, err } f, ok := v.(float64) if !ok { return 0, errors.New(fmt.Sprintf("%T unable", v)) } return int(f), nil }
[ "func", "(", "j", "*", "JSON", ")", "Int", "(", "name", "string", ")", "(", "int", ",", "error", ")", "{", "v", ",", "err", ":=", "j", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "f", ",", "ok", ":=", "v", ".", "(", "float64", ")", "\n", "if", "!", "ok", "{", "return", "0", ",", "errors", ".", "New", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ")", ")", "\n", "}", "\n\n", "return", "int", "(", "f", ")", ",", "nil", "\n", "}" ]
// Int returns an int if it exists within the marshalled JSON io.Reader.
[ "Int", "returns", "an", "int", "if", "it", "exists", "within", "the", "marshalled", "JSON", "io", ".", "Reader", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/json.go#L58-L70
4,869
paked/configure
json.go
Bool
func (j *JSON) Bool(name string) (bool, error) { v, err := j.value(name) if err != nil { return false, err } b, ok := v.(bool) if !ok { return false, errors.New("unable to cast") } return b, nil }
go
func (j *JSON) Bool(name string) (bool, error) { v, err := j.value(name) if err != nil { return false, err } b, ok := v.(bool) if !ok { return false, errors.New("unable to cast") } return b, nil }
[ "func", "(", "j", "*", "JSON", ")", "Bool", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "v", ",", "err", ":=", "j", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "b", ",", "ok", ":=", "v", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// Bool returns a bool if it exists within the marshalled JSON io.Reader.
[ "Bool", "returns", "a", "bool", "if", "it", "exists", "within", "the", "marshalled", "JSON", "io", ".", "Reader", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/json.go#L73-L85
4,870
paked/configure
json.go
String
func (j *JSON) String(name string) (string, error) { v, err := j.value(name) if err != nil { return "", err } s, ok := v.(string) if !ok { return "", errors.New(fmt.Sprintf("unable to cast %T", v)) } return s, nil }
go
func (j *JSON) String(name string) (string, error) { v, err := j.value(name) if err != nil { return "", err } s, ok := v.(string) if !ok { return "", errors.New(fmt.Sprintf("unable to cast %T", v)) } return s, nil }
[ "func", "(", "j", "*", "JSON", ")", "String", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "v", ",", "err", ":=", "j", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "s", ",", "ok", ":=", "v", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "errors", ".", "New", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ")", ")", "\n", "}", "\n\n", "return", "s", ",", "nil", "\n", "}" ]
// String returns a string if it exists within the marshalled JSON io.Reader.
[ "String", "returns", "a", "string", "if", "it", "exists", "within", "the", "marshalled", "JSON", "io", ".", "Reader", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/json.go#L88-L100
4,871
paked/configure
flag.go
NewFlag
func NewFlag() *Flag { f := &Flag{ args: os.Args, defaults: defaultsPrinter, } return f }
go
func NewFlag() *Flag { f := &Flag{ args: os.Args, defaults: defaultsPrinter, } return f }
[ "func", "NewFlag", "(", ")", "*", "Flag", "{", "f", ":=", "&", "Flag", "{", "args", ":", "os", ".", "Args", ",", "defaults", ":", "defaultsPrinter", ",", "}", "\n\n", "return", "f", "\n", "}" ]
// NewFlag returns a new instance of the Flag Checker, using os.Args as its // flag source.
[ "NewFlag", "returns", "a", "new", "instance", "of", "the", "Flag", "Checker", "using", "os", ".", "Args", "as", "its", "flag", "source", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/flag.go#L13-L20
4,872
paked/configure
flag.go
NewFlagWithUsage
func NewFlagWithUsage(defaulter func() string) *Flag { f := &Flag{ args: os.Args, defaults: defaulter, } return f }
go
func NewFlagWithUsage(defaulter func() string) *Flag { f := &Flag{ args: os.Args, defaults: defaulter, } return f }
[ "func", "NewFlagWithUsage", "(", "defaulter", "func", "(", ")", "string", ")", "*", "Flag", "{", "f", ":=", "&", "Flag", "{", "args", ":", "os", ".", "Args", ",", "defaults", ":", "defaulter", ",", "}", "\n\n", "return", "f", "\n", "}" ]
// NewFlagWithUsage returns a new instance of the Flag Checker with a custom // usage printer. It uses os.Args as its flag source.
[ "NewFlagWithUsage", "returns", "a", "new", "instance", "of", "the", "Flag", "Checker", "with", "a", "custom", "usage", "printer", ".", "It", "uses", "os", ".", "Args", "as", "its", "flag", "source", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/flag.go#L24-L31
4,873
paked/configure
flag.go
Int
func (f Flag) Int(name string) (int, error) { v, err := f.value(name) if err != nil { return 0, err } i, err := strconv.Atoi(v) if err != nil { return 0, err } return i, nil }
go
func (f Flag) Int(name string) (int, error) { v, err := f.value(name) if err != nil { return 0, err } i, err := strconv.Atoi(v) if err != nil { return 0, err } return i, nil }
[ "func", "(", "f", "Flag", ")", "Int", "(", "name", "string", ")", "(", "int", ",", "error", ")", "{", "v", ",", "err", ":=", "f", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "i", ",", "err", ":=", "strconv", ".", "Atoi", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "i", ",", "nil", "\n", "}" ]
// Int returns an int if it exists in the set flags.
[ "Int", "returns", "an", "int", "if", "it", "exists", "in", "the", "set", "flags", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/flag.go#L74-L86
4,874
paked/configure
flag.go
Bool
func (f *Flag) Bool(name string) (bool, error) { v, err := f.value(name) if err != nil { return false, err } return strconv.ParseBool(v) }
go
func (f *Flag) Bool(name string) (bool, error) { v, err := f.value(name) if err != nil { return false, err } return strconv.ParseBool(v) }
[ "func", "(", "f", "*", "Flag", ")", "Bool", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "v", ",", "err", ":=", "f", ".", "value", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "strconv", ".", "ParseBool", "(", "v", ")", "\n", "}" ]
// Bool returns a bool if it exists in the set flags.
[ "Bool", "returns", "a", "bool", "if", "it", "exists", "in", "the", "set", "flags", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/flag.go#L89-L96
4,875
paked/configure
flag.go
String
func (f Flag) String(name string) (string, error) { return f.value(name) }
go
func (f Flag) String(name string) (string, error) { return f.value(name) }
[ "func", "(", "f", "Flag", ")", "String", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "return", "f", ".", "value", "(", "name", ")", "\n", "}" ]
// String returns a string if it exists in the set flags.
[ "String", "returns", "a", "string", "if", "it", "exists", "in", "the", "set", "flags", "." ]
28f9c3f21a4454ca2e6ae1358856c6908293a46f
https://github.com/paked/configure/blob/28f9c3f21a4454ca2e6ae1358856c6908293a46f/flag.go#L99-L101
4,876
go-playground/log
log.go
SetContext
func SetContext(ctx context.Context, e Entry) context.Context { return context.WithValue(ctx, ctxIdent, e) }
go
func SetContext(ctx context.Context, e Entry) context.Context { return context.WithValue(ctx, ctxIdent, e) }
[ "func", "SetContext", "(", "ctx", "context", ".", "Context", ",", "e", "Entry", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxIdent", ",", "e", ")", "\n", "}" ]
// SetContext sets a log entry into the provided context
[ "SetContext", "sets", "a", "log", "entry", "into", "the", "provided", "context" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L49-L51
4,877
go-playground/log
log.go
GetContext
func GetContext(ctx context.Context) Entry { v := ctx.Value(ctxIdent) if v == nil { return newEntryWithFields(nil) } return v.(Entry) }
go
func GetContext(ctx context.Context) Entry { v := ctx.Value(ctxIdent) if v == nil { return newEntryWithFields(nil) } return v.(Entry) }
[ "func", "GetContext", "(", "ctx", "context", ".", "Context", ")", "Entry", "{", "v", ":=", "ctx", ".", "Value", "(", "ctxIdent", ")", "\n", "if", "v", "==", "nil", "{", "return", "newEntryWithFields", "(", "nil", ")", "\n", "}", "\n", "return", "v", ".", "(", "Entry", ")", "\n", "}" ]
// GetContext returns the log Entry found in the context, // or a new Default log Entry if none is found
[ "GetContext", "returns", "the", "log", "Entry", "found", "in", "the", "context", "or", "a", "new", "Default", "log", "Entry", "if", "none", "is", "found" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L55-L61
4,878
go-playground/log
log.go
HandleEntry
func HandleEntry(e Entry) { if !e.start.IsZero() { e = e.WithField("duration", time.Since(e.start)) } e.Timestamp = time.Now() rw.RLock() for _, h := range logHandlers[e.Level] { h.Log(e) } rw.RUnlock() }
go
func HandleEntry(e Entry) { if !e.start.IsZero() { e = e.WithField("duration", time.Since(e.start)) } e.Timestamp = time.Now() rw.RLock() for _, h := range logHandlers[e.Level] { h.Log(e) } rw.RUnlock() }
[ "func", "HandleEntry", "(", "e", "Entry", ")", "{", "if", "!", "e", ".", "start", ".", "IsZero", "(", ")", "{", "e", "=", "e", ".", "WithField", "(", "\"", "\"", ",", "time", ".", "Since", "(", "e", ".", "start", ")", ")", "\n", "}", "\n", "e", ".", "Timestamp", "=", "time", ".", "Now", "(", ")", "\n\n", "rw", ".", "RLock", "(", ")", "\n", "for", "_", ",", "h", ":=", "range", "logHandlers", "[", "e", ".", "Level", "]", "{", "h", ".", "Log", "(", "e", ")", "\n", "}", "\n", "rw", ".", "RUnlock", "(", ")", "\n", "}" ]
// HandleEntry handles the log entry and fans out to all handlers with the proper log level // This is exposed to allow for centralized logging whereby the log entry is marshalled, passed // to a central logging server, unmarshalled and finally fanned out from there.
[ "HandleEntry", "handles", "the", "log", "entry", "and", "fans", "out", "to", "all", "handlers", "with", "the", "proper", "log", "level", "This", "is", "exposed", "to", "allow", "for", "centralized", "logging", "whereby", "the", "log", "entry", "is", "marshalled", "passed", "to", "a", "central", "logging", "server", "unmarshalled", "and", "finally", "fanned", "out", "from", "there", "." ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L66-L77
4,879
go-playground/log
log.go
F
func F(key string, value interface{}) Field { return Field{Key: key, Value: value} }
go
func F(key string, value interface{}) Field { return Field{Key: key, Value: value} }
[ "func", "F", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "Field", "{", "return", "Field", "{", "Key", ":", "key", ",", "Value", ":", "value", "}", "\n", "}" ]
// F creates a new Field using the supplied key + value. // it is shorthand for defining field manually
[ "F", "creates", "a", "new", "Field", "using", "the", "supplied", "key", "+", "value", ".", "it", "is", "shorthand", "for", "defining", "field", "manually" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L81-L83
4,880
go-playground/log
log.go
AddHandler
func AddHandler(h Handler, levels ...Level) { rw.Lock() for _, level := range levels { handler := append(logHandlers[level], h) logHandlers[level] = handler } rw.Unlock() }
go
func AddHandler(h Handler, levels ...Level) { rw.Lock() for _, level := range levels { handler := append(logHandlers[level], h) logHandlers[level] = handler } rw.Unlock() }
[ "func", "AddHandler", "(", "h", "Handler", ",", "levels", "...", "Level", ")", "{", "rw", ".", "Lock", "(", ")", "\n", "for", "_", ",", "level", ":=", "range", "levels", "{", "handler", ":=", "append", "(", "logHandlers", "[", "level", "]", ",", "h", ")", "\n", "logHandlers", "[", "level", "]", "=", "handler", "\n", "}", "\n", "rw", ".", "Unlock", "(", ")", "\n", "}" ]
// AddHandler adds a new log handler and accepts which log levels that // handler will be triggered for
[ "AddHandler", "adds", "a", "new", "log", "handler", "and", "accepts", "which", "log", "levels", "that", "handler", "will", "be", "triggered", "for" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L87-L94
4,881
go-playground/log
log.go
RemoveHandler
func RemoveHandler(h Handler) { rw.Lock() OUTER: for lvl, handlers := range logHandlers { for i, handler := range handlers { if h == handler { n := append(handlers[:i], handlers[i+1:]...) if len(n) == 0 { delete(logHandlers, lvl) continue OUTER } logHandlers[lvl] = n continue OUTER } } } rw.Unlock() }
go
func RemoveHandler(h Handler) { rw.Lock() OUTER: for lvl, handlers := range logHandlers { for i, handler := range handlers { if h == handler { n := append(handlers[:i], handlers[i+1:]...) if len(n) == 0 { delete(logHandlers, lvl) continue OUTER } logHandlers[lvl] = n continue OUTER } } } rw.Unlock() }
[ "func", "RemoveHandler", "(", "h", "Handler", ")", "{", "rw", ".", "Lock", "(", ")", "\n", "OUTER", ":", "for", "lvl", ",", "handlers", ":=", "range", "logHandlers", "{", "for", "i", ",", "handler", ":=", "range", "handlers", "{", "if", "h", "==", "handler", "{", "n", ":=", "append", "(", "handlers", "[", ":", "i", "]", ",", "handlers", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "if", "len", "(", "n", ")", "==", "0", "{", "delete", "(", "logHandlers", ",", "lvl", ")", "\n", "continue", "OUTER", "\n", "}", "\n", "logHandlers", "[", "lvl", "]", "=", "n", "\n", "continue", "OUTER", "\n", "}", "\n", "}", "\n", "}", "\n", "rw", ".", "Unlock", "(", ")", "\n", "}" ]
// RemoveHandler removes an existing handler
[ "RemoveHandler", "removes", "an", "existing", "handler" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L97-L114
4,882
go-playground/log
log.go
RemoveHandlerLevels
func RemoveHandlerLevels(h Handler, levels ...Level) { rw.Lock() OUTER: for _, lvl := range levels { handlers := logHandlers[lvl] for i, handler := range handlers { if h == handler { n := append(handlers[:i], handlers[i+1:]...) if len(n) == 0 { delete(logHandlers, lvl) continue OUTER } logHandlers[lvl] = n continue OUTER } } } rw.Unlock() }
go
func RemoveHandlerLevels(h Handler, levels ...Level) { rw.Lock() OUTER: for _, lvl := range levels { handlers := logHandlers[lvl] for i, handler := range handlers { if h == handler { n := append(handlers[:i], handlers[i+1:]...) if len(n) == 0 { delete(logHandlers, lvl) continue OUTER } logHandlers[lvl] = n continue OUTER } } } rw.Unlock() }
[ "func", "RemoveHandlerLevels", "(", "h", "Handler", ",", "levels", "...", "Level", ")", "{", "rw", ".", "Lock", "(", ")", "\n", "OUTER", ":", "for", "_", ",", "lvl", ":=", "range", "levels", "{", "handlers", ":=", "logHandlers", "[", "lvl", "]", "\n", "for", "i", ",", "handler", ":=", "range", "handlers", "{", "if", "h", "==", "handler", "{", "n", ":=", "append", "(", "handlers", "[", ":", "i", "]", ",", "handlers", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "if", "len", "(", "n", ")", "==", "0", "{", "delete", "(", "logHandlers", ",", "lvl", ")", "\n", "continue", "OUTER", "\n", "}", "\n", "logHandlers", "[", "lvl", "]", "=", "n", "\n", "continue", "OUTER", "\n", "}", "\n", "}", "\n", "}", "\n", "rw", ".", "Unlock", "(", ")", "\n", "}" ]
// RemoveHandlerLevels removes the supplied levels, if no more levels exists for the handler // it will no longer be registered and need to to added via AddHandler again.
[ "RemoveHandlerLevels", "removes", "the", "supplied", "levels", "if", "no", "more", "levels", "exists", "for", "the", "handler", "it", "will", "no", "longer", "be", "registered", "and", "need", "to", "to", "added", "via", "AddHandler", "again", "." ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L118-L136
4,883
go-playground/log
log.go
WithTrace
func WithTrace() Entry { ne := newEntryWithFields(logFields) ne.start = time.Now() return ne }
go
func WithTrace() Entry { ne := newEntryWithFields(logFields) ne.start = time.Now() return ne }
[ "func", "WithTrace", "(", ")", "Entry", "{", "ne", ":=", "newEntryWithFields", "(", "logFields", ")", "\n", "ne", ".", "start", "=", "time", ".", "Now", "(", ")", "\n", "return", "ne", "\n", "}" ]
// WithTrace withh add duration of how long the between this function call and // the susequent log
[ "WithTrace", "withh", "add", "duration", "of", "how", "long", "the", "between", "this", "function", "call", "and", "the", "susequent", "log" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L159-L163
4,884
go-playground/log
log.go
WithError
func WithError(err error) Entry { ne := newEntryWithFields(logFields) return withErrFn(ne, err) }
go
func WithError(err error) Entry { ne := newEntryWithFields(logFields) return withErrFn(ne, err) }
[ "func", "WithError", "(", "err", "error", ")", "Entry", "{", "ne", ":=", "newEntryWithFields", "(", "logFields", ")", "\n", "return", "withErrFn", "(", "ne", ",", "err", ")", "\n", "}" ]
// WithError add a minimal stack trace to the log Entry
[ "WithError", "add", "a", "minimal", "stack", "trace", "to", "the", "log", "Entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L166-L169
4,885
go-playground/log
log.go
Infof
func Infof(s string, v ...interface{}) { e := newEntryWithFields(logFields) e.Infof(s, v...) }
go
func Infof(s string, v ...interface{}) { e := newEntryWithFields(logFields) e.Infof(s, v...) }
[ "func", "Infof", "(", "s", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "e", ":=", "newEntryWithFields", "(", "logFields", ")", "\n", "e", ".", "Infof", "(", "s", ",", "v", "...", ")", "\n", "}" ]
// Infof logs a normal. information, entry with formatiing
[ "Infof", "logs", "a", "normal", ".", "information", "entry", "with", "formatiing" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/log.go#L190-L193
4,886
go-playground/log
errors/segmentio/segmentio.go
ErrorsGoWithError
func ErrorsGoWithError(e log.Entry, err error) log.Entry { // normally would call newEntry, but instead will shallow copy // because it's not exposed. ne := new(log.Entry) *ne = *(&e) flds := make([]log.Field, 0, len(e.Fields)) flds = append(flds, e.Fields...) flds = append(flds, log.Field{Key: "error", Value: err.Error()}) ne.Fields = flds var frame errors.Frame _, types, tags, stacks, _ := errors.Inspect(err) if len(stacks) > 0 { frame = stacks[len(stacks)-1][0] } else { frame = errors.WithStack(err).(stackTracer).StackTrace()[2:][0] } name := fmt.Sprintf("%n", frame) file := fmt.Sprintf("%+s", frame) line := fmt.Sprintf("%d", frame) ne.Fields = append(ne.Fields, log.Field{Key: "source", Value: fmt.Sprintf("%s: %s:%s", name, file, line)}) for _, tag := range tags { ne.Fields = append(ne.Fields, log.Field{Key: tag.Name, Value: tag.Value}) } if len(types) > 0 { ne.Fields = append(ne.Fields, log.Field{Key: "types", Value: strings.Join(types, ",")}) } return *ne }
go
func ErrorsGoWithError(e log.Entry, err error) log.Entry { // normally would call newEntry, but instead will shallow copy // because it's not exposed. ne := new(log.Entry) *ne = *(&e) flds := make([]log.Field, 0, len(e.Fields)) flds = append(flds, e.Fields...) flds = append(flds, log.Field{Key: "error", Value: err.Error()}) ne.Fields = flds var frame errors.Frame _, types, tags, stacks, _ := errors.Inspect(err) if len(stacks) > 0 { frame = stacks[len(stacks)-1][0] } else { frame = errors.WithStack(err).(stackTracer).StackTrace()[2:][0] } name := fmt.Sprintf("%n", frame) file := fmt.Sprintf("%+s", frame) line := fmt.Sprintf("%d", frame) ne.Fields = append(ne.Fields, log.Field{Key: "source", Value: fmt.Sprintf("%s: %s:%s", name, file, line)}) for _, tag := range tags { ne.Fields = append(ne.Fields, log.Field{Key: tag.Name, Value: tag.Value}) } if len(types) > 0 { ne.Fields = append(ne.Fields, log.Field{Key: "types", Value: strings.Join(types, ",")}) } return *ne }
[ "func", "ErrorsGoWithError", "(", "e", "log", ".", "Entry", ",", "err", "error", ")", "log", ".", "Entry", "{", "// normally would call newEntry, but instead will shallow copy", "// because it's not exposed.", "ne", ":=", "new", "(", "log", ".", "Entry", ")", "\n", "*", "ne", "=", "*", "(", "&", "e", ")", "\n\n", "flds", ":=", "make", "(", "[", "]", "log", ".", "Field", ",", "0", ",", "len", "(", "e", ".", "Fields", ")", ")", "\n", "flds", "=", "append", "(", "flds", ",", "e", ".", "Fields", "...", ")", "\n", "flds", "=", "append", "(", "flds", ",", "log", ".", "Field", "{", "Key", ":", "\"", "\"", ",", "Value", ":", "err", ".", "Error", "(", ")", "}", ")", "\n", "ne", ".", "Fields", "=", "flds", "\n\n", "var", "frame", "errors", ".", "Frame", "\n\n", "_", ",", "types", ",", "tags", ",", "stacks", ",", "_", ":=", "errors", ".", "Inspect", "(", "err", ")", "\n\n", "if", "len", "(", "stacks", ")", ">", "0", "{", "frame", "=", "stacks", "[", "len", "(", "stacks", ")", "-", "1", "]", "[", "0", "]", "\n", "}", "else", "{", "frame", "=", "errors", ".", "WithStack", "(", "err", ")", ".", "(", "stackTracer", ")", ".", "StackTrace", "(", ")", "[", "2", ":", "]", "[", "0", "]", "\n", "}", "\n\n", "name", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "frame", ")", "\n", "file", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "frame", ")", "\n", "line", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "frame", ")", "\n", "ne", ".", "Fields", "=", "append", "(", "ne", ".", "Fields", ",", "log", ".", "Field", "{", "Key", ":", "\"", "\"", ",", "Value", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "file", ",", "line", ")", "}", ")", "\n\n", "for", "_", ",", "tag", ":=", "range", "tags", "{", "ne", ".", "Fields", "=", "append", "(", "ne", ".", "Fields", ",", "log", ".", "Field", "{", "Key", ":", "tag", ".", "Name", ",", "Value", ":", "tag", ".", "Value", "}", ")", "\n", "}", "\n", "if", "len", "(", "types", ")", ">", "0", "{", "ne", ".", "Fields", "=", "append", "(", "ne", ".", "Fields", ",", "log", ".", "Field", "{", "Key", ":", "\"", "\"", ",", "Value", ":", "strings", ".", "Join", "(", "types", ",", "\"", "\"", ")", "}", ")", "\n", "}", "\n", "return", "*", "ne", "\n", "}" ]
// ErrorsGoWithError is a custom WithError function that can be used by using log's // SetWithErrorFn function.
[ "ErrorsGoWithError", "is", "a", "custom", "WithError", "function", "that", "can", "be", "used", "by", "using", "log", "s", "SetWithErrorFn", "function", "." ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/errors/segmentio/segmentio.go#L18-L51
4,887
go-playground/log
handlers/console/console.go
New
func New(redirectSTDOut bool) *Console { if redirectSTDOut { done := make(chan struct{}) go handleStdLogger(done) <-done // have to wait, it was running too quickly and some messages can be lost } return &Console{ colors: defaultColors, writer: os.Stderr, timestampFormat: "2006-01-02 15:04:05.000000000Z07:00", displayColor: true, } }
go
func New(redirectSTDOut bool) *Console { if redirectSTDOut { done := make(chan struct{}) go handleStdLogger(done) <-done // have to wait, it was running too quickly and some messages can be lost } return &Console{ colors: defaultColors, writer: os.Stderr, timestampFormat: "2006-01-02 15:04:05.000000000Z07:00", displayColor: true, } }
[ "func", "New", "(", "redirectSTDOut", "bool", ")", "*", "Console", "{", "if", "redirectSTDOut", "{", "done", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "go", "handleStdLogger", "(", "done", ")", "\n", "<-", "done", "// have to wait, it was running too quickly and some messages can be lost", "\n", "}", "\n\n", "return", "&", "Console", "{", "colors", ":", "defaultColors", ",", "writer", ":", "os", ".", "Stderr", ",", "timestampFormat", ":", "\"", "\"", ",", "displayColor", ":", "true", ",", "}", "\n", "}" ]
// New returns a new instance of the console logger
[ "New", "returns", "a", "new", "instance", "of", "the", "console", "logger" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/handlers/console/console.go#L44-L57
4,888
go-playground/log
handlers/console/console.go
handleStdLogger
func handleStdLogger(done chan<- struct{}) { r, w := io.Pipe() defer func() { _ = r.Close() _ = w.Close() }() stdlog.SetOutput(w) scanner := bufio.NewScanner(r) go func() { done <- struct{}{} }() for scanner.Scan() { log.WithField("stdlog", true).Info(scanner.Text()) } }
go
func handleStdLogger(done chan<- struct{}) { r, w := io.Pipe() defer func() { _ = r.Close() _ = w.Close() }() stdlog.SetOutput(w) scanner := bufio.NewScanner(r) go func() { done <- struct{}{} }() for scanner.Scan() { log.WithField("stdlog", true).Info(scanner.Text()) } }
[ "func", "handleStdLogger", "(", "done", "chan", "<-", "struct", "{", "}", ")", "{", "r", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n", "defer", "func", "(", ")", "{", "_", "=", "r", ".", "Close", "(", ")", "\n", "_", "=", "w", ".", "Close", "(", ")", "\n", "}", "(", ")", "\n\n", "stdlog", ".", "SetOutput", "(", "w", ")", "\n\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "r", ")", "\n\n", "go", "func", "(", ")", "{", "done", "<-", "struct", "{", "}", "{", "}", "\n", "}", "(", ")", "\n\n", "for", "scanner", ".", "Scan", "(", ")", "{", "log", ".", "WithField", "(", "\"", "\"", ",", "true", ")", ".", "Info", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "}", "\n", "}" ]
// this will redirect the output of
[ "this", "will", "redirect", "the", "output", "of" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/handlers/console/console.go#L78-L96
4,889
go-playground/log
entry.go
Debug
func (e Entry) Debug(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = DebugLevel HandleEntry(e) }
go
func (e Entry) Debug(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = DebugLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Debug", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "DebugLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Debug logs a debug entry
[ "Debug", "logs", "a", "debug", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L61-L65
4,890
go-playground/log
entry.go
Info
func (e Entry) Info(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = InfoLevel HandleEntry(e) }
go
func (e Entry) Info(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = InfoLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Info", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "InfoLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Info logs a normal. information, entry
[ "Info", "logs", "a", "normal", ".", "information", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L75-L79
4,891
go-playground/log
entry.go
Infof
func (e Entry) Infof(s string, v ...interface{}) { e.Message = fmt.Sprintf(s, v...) e.Level = InfoLevel HandleEntry(e) }
go
func (e Entry) Infof(s string, v ...interface{}) { e.Message = fmt.Sprintf(s, v...) e.Level = InfoLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Infof", "(", "s", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprintf", "(", "s", ",", "v", "...", ")", "\n", "e", ".", "Level", "=", "InfoLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Infof logs a normal. information, entry with formatting
[ "Infof", "logs", "a", "normal", ".", "information", "entry", "with", "formatting" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L82-L86
4,892
go-playground/log
entry.go
Notice
func (e Entry) Notice(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = NoticeLevel HandleEntry(e) }
go
func (e Entry) Notice(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = NoticeLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Notice", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "NoticeLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Notice logs a notice log entry
[ "Notice", "logs", "a", "notice", "log", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L89-L93
4,893
go-playground/log
entry.go
Warn
func (e Entry) Warn(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = WarnLevel HandleEntry(e) }
go
func (e Entry) Warn(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = WarnLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Warn", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "WarnLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Warn logs a warn log entry
[ "Warn", "logs", "a", "warn", "log", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L103-L107
4,894
go-playground/log
entry.go
Panic
func (e Entry) Panic(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = PanicLevel HandleEntry(e) exitFunc(1) }
go
func (e Entry) Panic(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = PanicLevel HandleEntry(e) exitFunc(1) }
[ "func", "(", "e", "Entry", ")", "Panic", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "PanicLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "exitFunc", "(", "1", ")", "\n", "}" ]
// Panic logs a panic log entry
[ "Panic", "logs", "a", "panic", "log", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L117-L122
4,895
go-playground/log
entry.go
Alert
func (e Entry) Alert(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = AlertLevel HandleEntry(e) }
go
func (e Entry) Alert(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = AlertLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Alert", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "AlertLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Alert logs an alert log entry
[ "Alert", "logs", "an", "alert", "log", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L133-L137
4,896
go-playground/log
entry.go
Fatal
func (e Entry) Fatal(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = FatalLevel HandleEntry(e) exitFunc(1) }
go
func (e Entry) Fatal(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = FatalLevel HandleEntry(e) exitFunc(1) }
[ "func", "(", "e", "Entry", ")", "Fatal", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "FatalLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "exitFunc", "(", "1", ")", "\n", "}" ]
// Fatal logs a fatal log entry
[ "Fatal", "logs", "a", "fatal", "log", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L147-L152
4,897
go-playground/log
entry.go
Error
func (e Entry) Error(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = ErrorLevel HandleEntry(e) }
go
func (e Entry) Error(v ...interface{}) { e.Message = fmt.Sprint(v...) e.Level = ErrorLevel HandleEntry(e) }
[ "func", "(", "e", "Entry", ")", "Error", "(", "v", "...", "interface", "{", "}", ")", "{", "e", ".", "Message", "=", "fmt", ".", "Sprint", "(", "v", "...", ")", "\n", "e", ".", "Level", "=", "ErrorLevel", "\n", "HandleEntry", "(", "e", ")", "\n", "}" ]
// Error logs an error log entry
[ "Error", "logs", "an", "error", "log", "entry" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/entry.go#L163-L167
4,898
go-playground/log
errors/pkg/pkg.go
ErrorsWithError
func ErrorsWithError(e log.Entry, err error) log.Entry { // normally would call newEntry, but instead will shallow copy // because it's not exposed. ne := new(log.Entry) *ne = *(&e) flds := make([]log.Field, 0, len(e.Fields)) flds = append(flds, e.Fields...) flds = append(flds, log.Field{Key: "error", Value: err.Error()}) ne.Fields = flds var frame errors.Frame if s, ok := err.(stackTracer); ok { frame = s.StackTrace()[0] } else { frame = errors.WithStack(err).(stackTracer).StackTrace()[2:][0] } name := fmt.Sprintf("%n", frame) file := fmt.Sprintf("%+s", frame) line := fmt.Sprintf("%d", frame) parts := strings.Split(file, "\n\t") if len(parts) > 1 { file = parts[1] } ne.Fields = append(ne.Fields, log.Field{Key: "source", Value: fmt.Sprintf("%s: %s:%s", name, file, line)}) return *ne }
go
func ErrorsWithError(e log.Entry, err error) log.Entry { // normally would call newEntry, but instead will shallow copy // because it's not exposed. ne := new(log.Entry) *ne = *(&e) flds := make([]log.Field, 0, len(e.Fields)) flds = append(flds, e.Fields...) flds = append(flds, log.Field{Key: "error", Value: err.Error()}) ne.Fields = flds var frame errors.Frame if s, ok := err.(stackTracer); ok { frame = s.StackTrace()[0] } else { frame = errors.WithStack(err).(stackTracer).StackTrace()[2:][0] } name := fmt.Sprintf("%n", frame) file := fmt.Sprintf("%+s", frame) line := fmt.Sprintf("%d", frame) parts := strings.Split(file, "\n\t") if len(parts) > 1 { file = parts[1] } ne.Fields = append(ne.Fields, log.Field{Key: "source", Value: fmt.Sprintf("%s: %s:%s", name, file, line)}) return *ne }
[ "func", "ErrorsWithError", "(", "e", "log", ".", "Entry", ",", "err", "error", ")", "log", ".", "Entry", "{", "// normally would call newEntry, but instead will shallow copy", "// because it's not exposed.", "ne", ":=", "new", "(", "log", ".", "Entry", ")", "\n", "*", "ne", "=", "*", "(", "&", "e", ")", "\n\n", "flds", ":=", "make", "(", "[", "]", "log", ".", "Field", ",", "0", ",", "len", "(", "e", ".", "Fields", ")", ")", "\n", "flds", "=", "append", "(", "flds", ",", "e", ".", "Fields", "...", ")", "\n", "flds", "=", "append", "(", "flds", ",", "log", ".", "Field", "{", "Key", ":", "\"", "\"", ",", "Value", ":", "err", ".", "Error", "(", ")", "}", ")", "\n", "ne", ".", "Fields", "=", "flds", "\n\n", "var", "frame", "errors", ".", "Frame", "\n\n", "if", "s", ",", "ok", ":=", "err", ".", "(", "stackTracer", ")", ";", "ok", "{", "frame", "=", "s", ".", "StackTrace", "(", ")", "[", "0", "]", "\n", "}", "else", "{", "frame", "=", "errors", ".", "WithStack", "(", "err", ")", ".", "(", "stackTracer", ")", ".", "StackTrace", "(", ")", "[", "2", ":", "]", "[", "0", "]", "\n", "}", "\n\n", "name", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "frame", ")", "\n", "file", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "frame", ")", "\n", "line", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "frame", ")", "\n", "parts", ":=", "strings", ".", "Split", "(", "file", ",", "\"", "\\n", "\\t", "\"", ")", "\n", "if", "len", "(", "parts", ")", ">", "1", "{", "file", "=", "parts", "[", "1", "]", "\n", "}", "\n", "ne", ".", "Fields", "=", "append", "(", "ne", ".", "Fields", ",", "log", ".", "Field", "{", "Key", ":", "\"", "\"", ",", "Value", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "file", ",", "line", ")", "}", ")", "\n", "return", "*", "ne", "\n", "}" ]
// ErrorsWithError is a custom WithError function that can be used by using log's // SetWithErrorFn function.
[ "ErrorsWithError", "is", "a", "custom", "WithError", "function", "that", "can", "be", "used", "by", "using", "log", "s", "SetWithErrorFn", "function", "." ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/errors/pkg/pkg.go#L17-L45
4,899
go-playground/log
handlers/syslog/syslog.go
GetDisplayColor
func (s *Syslog) GetDisplayColor(level log.Level) ansi.EscSeq { return s.colors[level] }
go
func (s *Syslog) GetDisplayColor(level log.Level) ansi.EscSeq { return s.colors[level] }
[ "func", "(", "s", "*", "Syslog", ")", "GetDisplayColor", "(", "level", "log", ".", "Level", ")", "ansi", ".", "EscSeq", "{", "return", "s", ".", "colors", "[", "level", "]", "\n", "}" ]
// GetDisplayColor returns the color for the given log level
[ "GetDisplayColor", "returns", "the", "color", "for", "the", "given", "log", "level" ]
fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19
https://github.com/go-playground/log/blob/fdcdf507e3bf20900bc1a44b0cbd73fee5bcbe19/handlers/syslog/syslog.go#L93-L95