本文整理汇总了Golang中github.com/ardanlabs/kit/log.Dev函数的典型用法代码示例。如果您正苦于以下问题:Golang Dev函数的具体用法?Golang Dev怎么用?Golang Dev使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dev函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpsertForm
// UpsertForm upserts the provided form into the MongoDB database collection and
// creates a gallery based on it.
func UpsertForm(context interface{}, db *db.DB, f *form.Form) error {
log.Dev(context, "UpsertForm", "Started : Form[%s]", f.ID.Hex())
var isNewForm bool
// If there was no ID provided, we should set one. UpsertForm might optionally add
// a form ID to ensure that we don't duplicate the FormGallery.
if f.ID.Hex() == "" {
isNewForm = true
}
if err := form.Upsert(context, db, f); err != nil {
log.Error(context, "UpsertForm", err, "Completed")
return err
}
if isNewForm {
// Create the new gallery that we will create that is based on the current
// form ID.
g := gallery.Gallery{
FormID: f.ID,
}
if err := gallery.Create(context, db, &g); err != nil {
log.Error(context, "UpsertForm", err, "Completed")
return err
}
}
log.Dev(context, "UpsertForm", "Completed")
return nil
}
示例2: Mongo
// Mongo handles session management.
func Mongo(h app.Handler) app.Handler {
// Check if mongodb is configured.
dbName, err := cfg.String(cfgMongoDB)
if err != nil {
return func(c *app.Context) error {
log.Dev(c.SessionID, "Mongo", "******> Mongo Not Configured")
return h(c)
}
}
// Wrap the handlers inside a session copy/close.
return func(c *app.Context) error {
mgoDB, err := db.NewMGO("Mongo", dbName)
if err != nil {
log.Error(c.SessionID, "Mongo", err, "Method[%s] URL[%s] RADDR[%s]", c.Request.Method, c.Request.URL.Path, c.Request.RemoteAddr)
return app.ErrDBNotConfigured
}
log.Dev(c.SessionID, "Mongo", "******> Capture Mongo Session")
c.DB = mgoDB
defer func() {
log.Dev(c.SessionID, "Mongo", "******> Release Mongo Session")
mgoDB.CloseMGO("Mongo")
}()
return h(c)
}
}
示例3: newClient
// newClient creates a new client for an incoming connection.
func newClient(context string, t *TCP, conn net.Conn) *client {
ipAddress := conn.RemoteAddr().String()
log.Dev(context, "newClient", "Started : IPAddress[%s]", ipAddress)
// Ask the user to bind the reader and writer they want to
// use for this connection.
r, w := t.ConnHandler.Bind(context, conn)
c := client{
context: context,
t: t,
conn: conn,
ipAddress: ipAddress,
reader: r,
writer: w,
}
// Check to see if this connection is ipv6.
if raddr := conn.RemoteAddr().(*net.TCPAddr); raddr.IP.To4() == nil {
c.isIPv6 = true
}
// Launch a goroutine for this connection.
c.wg.Add(1)
go c.read()
log.Dev(context, "newClient", "Completed")
return &c
}
示例4: DeleteSubmission
// DeleteSubmission deletes a submission as well as updating a form's stats.
func DeleteSubmission(context interface{}, db *db.DB, id, formID string) error {
log.Dev(context, "DeleteSubmission", "Started : Submission[%s]", id)
if !bson.IsObjectIdHex(id) {
log.Error(context, "DeleteSubmission", ErrInvalidID, "Completed")
return ErrInvalidID
}
if !bson.IsObjectIdHex(formID) {
log.Error(context, "Delete", ErrInvalidID, "Completed")
return ErrInvalidID
}
if err := submission.Delete(context, db, id); err != nil {
log.Error(context, "DeleteSubmission", err, "Completed")
return err
}
if _, err := form.UpdateStats(context, db, formID); err != nil {
log.Error(context, "DeleteSubmission", err, "Completed")
return err
}
log.Dev(context, "DeleteSubmission", "Started")
return nil
}
示例5: New
// New creates a new Pool.
func New(context interface{}, name string, cfg Config) (*Pool, error) {
log.Dev(context, "New", "Started : Name[%s]", name)
if cfg.MinRoutines == nil {
return nil, ErrNilMinRoutines
}
if cfg.MinRoutines() <= 0 {
return nil, ErrInvalidMinRoutines
}
if cfg.MaxRoutines == nil {
return nil, ErrNilMaxRoutines
}
if cfg.MaxRoutines() < cfg.MinRoutines() {
return nil, ErrInvalidMaxRoutines
}
p := Pool{
Config: cfg,
Name: name,
tasks: make(chan doWork),
control: make(chan int),
kill: make(chan struct{}),
shutdown: make(chan struct{}),
}
p.manager(context)
p.add(context, cfg.MinRoutines())
log.Dev(context, "New", "Completed")
return &p, nil
}
示例6: GetByName
// GetByName retrieves the document for the specified query mask.
func GetByName(context interface{}, db *db.DB, collection string, field string) (Mask, error) {
log.Dev(context, "GetByName", "Started : Collection[%s] Field[%s]", collection, field)
key := "gbn" + collection + field
if v, found := cache.Get(key); found {
mask := v.(Mask)
log.Dev(context, "GetByName", "Completed : CACHE : Mask[%+v]", mask)
return mask, nil
}
var mask Mask
f := func(c *mgo.Collection) error {
q := bson.M{"collection": collection, "field": field}
log.Dev(context, "GetByName", "MGO : db.%s.findOne(%s)", c.Name, mongo.Query(q))
return c.Find(q).One(&mask)
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
if err == mgo.ErrNotFound {
err = ErrNotFound
}
log.Error(context, "GetByName", err, "Completed")
return Mask{}, err
}
cache.Set(key, mask, gc.DefaultExpiration)
log.Dev(context, "GetByName", "Completed : Mask[%+v]", mask)
return mask, nil
}
示例7: GetByIDs
// GetByIDs retrieves items by ID from Mongo.
func GetByIDs(context interface{}, db *db.DB, ids []string) ([]Item, error) {
log.Dev(context, "GetByIDs", "Started : IDs%v", ids)
// Get the items from Mongo.
var items []Item
f := func(c *mgo.Collection) error {
q := bson.M{"item_id": bson.M{"$in": ids}}
log.Dev(context, "Find", "MGO : db.%s.find(%s)", c.Name, mongo.Query(q))
return c.Find(q).All(&items)
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
if err == mgo.ErrNotFound {
err = ErrNotFound
}
log.Error(context, "GetByIDs", err, "Completed")
return items, err
}
// If we got an unexpected number of items, throw an error.
if len(ids) < len(items) {
return nil, fmt.Errorf("Expected %d items, got %d: ", len(ids), len(items))
}
log.Dev(context, "GetByIDs", "Completed")
return items, nil
}
示例8: Midware
// Midware handles databse session management and manages a MongoDB session.
func Midware(mongoURI *url.URL) web.Middleware {
// Create the middleware that we can use to create MongoDB sessions with.
m := func(next web.Handler) web.Handler {
// Create the handler that will be attached in the middleware chain.
h := func(c *web.Context) error {
// Pull in the mongo session from the master session so we can load it
// onto the request context. It is keyed by the path on the uri.
db, err := kitdb.NewMGO(c.SessionID, mongoURI.Path)
if err != nil {
log.Error(c.SessionID, "mongo : Midware", err, "Method[%s] URL[%s] RADDR[%s]", c.Request.Method, c.Request.URL.Path, c.Request.RemoteAddr)
return web.ErrDBNotConfigured
}
// Load the mongo database onto the request context.
c.Ctx["DB"] = db
log.Dev(c.SessionID, "mongo : Midware", "Capture Mongo Session")
// Close the MongoDB session when the handler returns.
defer func() {
log.Dev(c.SessionID, "mongo : Midware", "Release Mongo Session")
db.CloseMGO(c.SessionID)
}()
return next(c)
}
return h
}
return m
}
示例9: Update
// Update updates the form gallery in the MongoDB database
// collection.
func Update(context interface{}, db *db.DB, id string, gallery *Gallery) error {
log.Dev(context, "Update", "Started : Gallery[%s]", id)
if !bson.IsObjectIdHex(id) {
log.Error(context, "Update", ErrInvalidID, "Completed")
return ErrInvalidID
}
if err := gallery.Validate(); err != nil {
log.Error(context, "Update", err, "Completed")
return err
}
objectID := bson.ObjectIdHex(id)
gallery.DateUpdated = time.Now()
f := func(c *mgo.Collection) error {
log.Dev(context, "Update", "MGO : db.%s.update(%s, %s)", c.Name, mongo.Query(objectID), mongo.Query(gallery))
return c.UpdateId(objectID, gallery)
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
log.Error(context, "Update", err, "Completed")
return err
}
log.Dev(context, "Update", "Completed")
return nil
}
示例10: Auth
// Auth handles token authentication.
func Auth(h app.Handler) app.Handler {
// Check if authentication is turned off.
on, err := cfg.Bool(cfgAuth)
if err == nil && !on {
return func(c *app.Context) error {
log.Dev(c.SessionID, "Auth", "******> Authentication Off")
return h(c)
}
}
// Turn authentication on.
return func(c *app.Context) error {
token := c.Request.Header.Get("Authorization")
log.Dev(c.SessionID, "Auth", "Started : Token[%s]", token)
if len(token) < 5 || token[0:5] != "Basic" {
log.Error(c.SessionID, "Auth", app.ErrNotAuthorized, "Validating token")
return app.ErrNotAuthorized
}
var err error
if c.User, err = auth.ValidateWebToken(c.SessionID, c.DB, token[6:]); err != nil {
log.Error(c.SessionID, "Auth", err, "Validating token")
return app.ErrNotAuthorized
}
log.Dev(c.SessionID, "Auth", "Completed")
return h(c)
}
}
示例11: GetAll
// GetAll retrieves a list of regexs.
func GetAll(context interface{}, db *db.DB, tags []string) ([]Regex, error) {
log.Dev(context, "GetAll", "Started : Tags[%v]", tags)
key := "grs" + strings.Join(tags, "-")
if v, found := cache.Get(key); found {
rgxs := v.([]Regex)
log.Dev(context, "GetAll", "Completed : CACHE : Rgxs[%d]", len(rgxs))
return rgxs, nil
}
var rgxs []Regex
f := func(c *mgo.Collection) error {
log.Dev(context, "GetAll", "MGO : db.%s.find({}).sort([\"name\"])", c.Name)
return c.Find(nil).All(&rgxs)
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
if err == mgo.ErrNotFound {
err = ErrNotFound
}
log.Error(context, "GetAll", err, "Completed")
return nil, err
}
if rgxs == nil {
log.Error(context, "GetAll", ErrNotFound, "Completed")
return nil, ErrNotFound
}
cache.Set(key, rgxs, gc.DefaultExpiration)
log.Dev(context, "GetAll", "Completed : Rgxs[%d]", len(rgxs))
return rgxs, nil
}
示例12: Remove
// Remove removes an item into the items collection and remove any
// corresponding quads from the graph database.
func Remove(context interface{}, db *db.DB, graph *cayley.Handle, itemID string) error {
log.Dev(context, "Remove", "Started : ID[%s]", itemID)
// Get the item from the items collection.
items, err := item.GetByIDs(context, db, []string{itemID})
if err != nil {
log.Error(context, "Remove", err, "Completed")
return err
}
// Prepare the item map data.
itmMap := map[string]interface{}{
"item_id": items[0].ID,
"type": items[0].Type,
"version": items[0].Version,
"data": items[0].Data,
}
// Remove the corresponding relationships from the graph.
if err := wire.RemoveFromGraph(context, db, graph, itmMap); err != nil {
log.Error(context, "Remove", err, "Completed")
return err
}
// Delete the item.
if err := item.Delete(context, db, itemID); err != nil {
log.Error(context, "Remove", err, "Completed")
return err
}
log.Dev(context, "Remove", "Completed")
return nil
}
示例13: Count
// Count returns the count of current submissions for a given
// form id in the Form Submissions MongoDB database collection.
func Count(context interface{}, db *db.DB, formID string) (int, error) {
log.Dev(context, "Count", "Completed : Form[%s]", formID)
if !bson.IsObjectIdHex(formID) {
log.Error(context, "Count", ErrInvalidID, "Completed")
return 0, ErrInvalidID
}
formObjectID := bson.ObjectIdHex(formID)
var count int
f := func(c *mgo.Collection) error {
var err error
q := bson.M{
"form_id": formObjectID,
}
log.Dev(context, "Count", "MGO : db.%s.find(%s).count()", c.Name, mongo.Query(q))
count, err = c.Find(q).Count()
return err
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
log.Error(context, "Count", err, "Completed")
return 0, err
}
log.Dev(context, "Count", "Completed")
return count, nil
}
示例14: RetrieveMany
// RetrieveMany retrieves a list of Submission's from the MongoDB database collection.
func RetrieveMany(context interface{}, db *db.DB, ids []string) ([]Submission, error) {
log.Dev(context, "RetrieveMany", "Started")
var objectIDs = make([]bson.ObjectId, len(ids))
for i, id := range ids {
if !bson.IsObjectIdHex(id) {
log.Error(context, "RetrieveMany", ErrInvalidID, "Completed")
return nil, ErrInvalidID
}
objectIDs[i] = bson.ObjectIdHex(id)
}
var submissions []Submission
f := func(c *mgo.Collection) error {
q := bson.M{
"_id": bson.M{
"$in": objectIDs,
},
}
log.Dev(context, "RetrieveMany", "MGO : db.%s.find(%s)", c.Name, mongo.Query(q))
return c.Find(q).All(&submissions)
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
log.Error(context, "RetrieveMany", err, "Completed")
return nil, err
}
log.Dev(context, "RetrieveMany", "Started")
return submissions, nil
}
示例15: UpdateStatus
// UpdateStatus updates a form submissions status inside the MongoDB database
// collection.
func UpdateStatus(context interface{}, db *db.DB, id, status string) (*Submission, error) {
log.Dev(context, "UpdateStatus", "Started : Submission[%s]", id)
if !bson.IsObjectIdHex(id) {
log.Error(context, "UpdateStatus", ErrInvalidID, "Completed")
return nil, ErrInvalidID
}
objectID := bson.ObjectIdHex(id)
f := func(c *mgo.Collection) error {
u := bson.M{
"$set": bson.M{
"status": status,
"date_updated": time.Now(),
},
}
log.Dev(context, "UpdateStatus", "MGO : db.%s.update(%s, %s)", c.Name, mongo.Query(objectID), mongo.Query(u))
return c.UpdateId(objectID, u)
}
if err := db.ExecuteMGO(context, Collection, f); err != nil {
log.Error(context, "UpdateStatus", err, "Completed")
return nil, err
}
submission, err := Retrieve(context, db, id)
if err != nil {
log.Error(context, "UpdateStatus", err, "Completed")
return nil, err
}
log.Dev(context, "UpdateStatus", "Completed")
return submission, nil
}