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


Golang webfw.GetLogger函数代码示例

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


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

示例1: Handler

func (con Component) Handler(c context.Context) http.Handler {
	mw, i18nFound := con.dispatcher.Middleware("I18N")
	logger := webfw.GetLogger(c)

	rnd := renderer.NewRenderer(con.dispatcher.Config.Renderer.Dir, "raw.tmpl")
	rnd.Delims("{%", "%}")

	if i18nFound {
		if i18n, ok := mw.(middleware.I18N); ok {
			rnd.Funcs(i18n.TemplateFuncMap())
		}
	} else {
		logger.Infoln("I18N middleware not found")
	}

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		params := webfw.GetParams(c, r)

		err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern},
			c.GetAll(r), "components/"+params["name"]+".tmpl")

		if err != nil {
			webfw.GetLogger(c).Print(err)
		}
	})
}
开发者ID:RavenB,项目名称:readeef,代码行数:26,代码来源:component.go

示例2: Handler

func (con App) Handler(c context.Context) http.Handler {
	cfg := readeef.GetConfig(c)
	rnd := webfw.GetRenderer(c)

	if cfg.Logger.Level == "debug" {
		rnd.SkipCache(true)
	}

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		action := webfw.GetMultiPatternIdentifier(c, r)

		data := renderer.RenderData{}
		if action == "history" {
			params := webfw.GetParams(c, r)
			data["history"] = "/web/" + params["history"]
		}

		if r.Method != "HEAD" {
			err := rnd.Render(w, data, c.GetAll(r), "app.tmpl")
			if err != nil {
				webfw.GetLogger(c).Print(err)
			}
		}

		w.Header().Set("X-Readeef", "1")
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:27,代码来源:app.go

示例3: Handler

func (con Auth) Handler(c context.Context) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		action := webfw.GetMultiPatternIdentifier(c, r)
		sess := webfw.GetSession(c, r)

		var resp responseError

		switch action {
		case "auth-data":
			user := readeef.GetUser(c, r)
			resp = getAuthData(user, sess, con.capabilities)
		case "logout":
			resp = logout(sess)
		}

		var b []byte
		if resp.err == nil {
			b, resp.err = json.Marshal(resp.val)
		}
		if resp.err == nil {
			w.Write(b)
		} else {
			webfw.GetLogger(c).Print(resp.err)

			w.WriteHeader(http.StatusInternalServerError)
			return
		}
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:29,代码来源:auth.go

示例4: Handler

func (con UserSettings) Handler(c context.Context) http.Handler {
	cfg := readeef.GetConfig(c)
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user := readeef.GetUser(c, r)

		params := webfw.GetParams(c, r)
		attr := params["attribute"]

		var resp responseError
		if r.Method == "GET" {
			resp = getUserAttribute(user, attr)
		} else if r.Method == "POST" {
			buf := util.BufferPool.GetBuffer()
			defer util.BufferPool.Put(buf)

			buf.ReadFrom(r.Body)

			resp = setUserAttribute(user, []byte(cfg.Auth.Secret), attr, buf.Bytes())
		}

		var b []byte
		if resp.err == nil {
			b, resp.err = json.Marshal(resp.val)
		}

		if resp.err != nil {
			webfw.GetLogger(c).Print(resp.err)

			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		w.Write(b)
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:35,代码来源:user-settings.go

示例5: Handler

func (con FeedUpdateNotificator) Handler(c context.Context) http.HandlerFunc {
	var mutex sync.RWMutex

	receivers := make(map[chan readeef.Feed]bool)

	go func() {
		for {
			select {
			case feed := <-con.updateFeed:
				mutex.RLock()

				readeef.Debug.Printf("Feed %s updated. Notifying %d receivers.", feed.Link, len(receivers))
				for receiver, _ := range receivers {
					receiver <- feed
				}

				mutex.RUnlock()
			}
		}
	}()

	return func(w http.ResponseWriter, r *http.Request) {
		var err error

		receiver := make(chan readeef.Feed)

		mutex.Lock()
		receivers[receiver] = true
		mutex.Unlock()
		defer func() {
			mutex.Lock()
			delete(receivers, receiver)
			mutex.Unlock()
		}()

		f := <-receiver
		readeef.Debug.Println("Feed " + f.Link + " updated")

		resp := map[string]interface{}{"Feed": feed{
			Id: f.Id, Title: f.Title, Description: f.Description,
			Link: f.Link, Image: f.Image,
		}}

		var b []byte
		if err == nil {
			b, err = json.Marshal(resp)
		}
		if err != nil {
			webfw.GetLogger(c).Print(err)

			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		w.Write(b)
	}
}
开发者ID:yourchanges,项目名称:readeef,代码行数:57,代码来源:feed_update_notificator.go

示例6: Handler

func (con App) Handler(c context.Context) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		rnd := webfw.GetRenderer(c)

		err := rnd.Render(w, nil, c.GetAll(r), "app.tmpl")
		if err != nil {
			webfw.GetLogger(c).Print(err)
		}
	}
}
开发者ID:yourchanges,项目名称:readeef,代码行数:10,代码来源:app.go

示例7: Handler

func (con Article) Handler(c context.Context) http.Handler {
	logger := webfw.GetLogger(c)
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user := readeef.GetUser(c, r)

		params := webfw.GetParams(c, r)
		action := webfw.GetMultiPatternIdentifier(c, r)

		logger.Infof("Invoking Article controller with action '%s', article id '%s'\n", action, params["article-id"])

		var articleId int64
		var resp responseError

		articleId, resp.err = strconv.ParseInt(params["article-id"], 10, 64)

		if resp.err == nil {
			id := data.ArticleId(articleId)
			switch action {
			case "fetch":
				resp = fetchArticle(user, id)
			case "read":
				resp = articleReadState(user, id, params["value"] == "true")
			case "favorite":
				resp = articleFavoriteState(user, id, params["value"] == "true")
			case "format":
				resp = formatArticle(user, id, con.extractor, webfw.GetConfig(c), con.config)
			}
		}

		var b []byte
		if resp.err == nil {
			b, resp.err = json.Marshal(resp.val)
		}

		if resp.err == nil {
			w.Write(b)
		} else {
			webfw.GetLogger(c).Print(resp.err)

			w.WriteHeader(http.StatusInternalServerError)
		}
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:43,代码来源:article.go

示例8: Handler

func (con Component) Handler(c context.Context) http.Handler {
	i18nmw, i18nFound := con.dispatcher.Middleware("I18N")
	urlmw, urlFound := con.dispatcher.Middleware("Url")
	logger := webfw.GetLogger(c)
	cfg := readeef.GetConfig(c)

	rnd := renderer.NewRenderer(con.dispatcher.Config.Renderer.Dir, "raw.tmpl")
	rnd.Delims("{%", "%}")

	if cfg.Logger.Level == "debug" {
		rnd.SkipCache(true)
	}

	if i18nFound {
		if i18n, ok := i18nmw.(middleware.I18N); ok {
			rnd.Funcs(i18n.TemplateFuncMap())
		}
	} else {
		logger.Infoln("I18N middleware not found")
	}

	if urlFound {
		if url, ok := urlmw.(middleware.Url); ok {
			rnd.Funcs(url.TemplateFuncMap(c))
		}
	} else {
		logger.Infoln("Url middleware not found")
	}

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		params := webfw.GetParams(c, r)

		if r.Method != "HEAD" {
			err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern, "config": cfg},
				c.GetAll(r), "components/"+params["name"]+".tmpl")

			if err != nil {
				webfw.GetLogger(c).Print(err)
			}
		}
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:42,代码来源:component.go

示例9: Handler

func (con User) Handler(c context.Context) http.Handler {
	cfg := readeef.GetConfig(c)
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user := readeef.GetUser(c, r)

		action := webfw.GetMultiPatternIdentifier(c, r)
		params := webfw.GetParams(c, r)

		var resp responseError
		switch action {
		case "list":
			resp = listUsers(user)
		case "add":
			buf := util.BufferPool.GetBuffer()
			defer util.BufferPool.Put(buf)

			buf.ReadFrom(r.Body)

			resp = addUser(user, data.Login(params["login"]), buf.String(), []byte(cfg.Auth.Secret))
		case "remove":
			resp = removeUser(user, data.Login(params["login"]))
		case "setAttr":
			resp = setAttributeForUser(user, []byte(cfg.Auth.Secret), data.Login(params["login"]), params["attr"], []byte(params["value"]))
		}

		switch resp.err {
		case errForbidden:
			w.WriteHeader(http.StatusForbidden)
			return
		case errUserExists:
			resp.val["Error"] = true
			resp.val["ErrorType"] = resp.errType
			resp.err = nil
		case errCurrentUser:
			resp.val["Error"] = true
			resp.val["ErrorType"] = resp.errType
			resp.err = nil
		}

		var b []byte
		if resp.err == nil {
			b, resp.err = json.Marshal(resp.val)
		}
		if resp.err != nil {
			webfw.GetLogger(c).Print(resp.err)

			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		w.Write(b)
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:53,代码来源:user.go

示例10: Handler

func (con Login) Handler(c context.Context) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		l := webfw.GetLogger(c)
		sess := webfw.GetSession(c, r)
		renderData := renderer.RenderData{}

		if r.Method == "GET" {
			if v, ok := sess.Flash("form-error"); ok {
				renderData["form-error"] = v
			}
		} else {
			if err := r.ParseForm(); err != nil {
				l.Fatal(err)
			}
			username := data.Login(r.Form.Get("username"))
			password := r.Form.Get("password")

			repo := GetRepo(c)
			conf := GetConfig(c)
			u := repo.UserByLogin(username)

			formError := false
			if u.Err() != nil {
				sess.SetFlash("form-error", "login-incorrect")
				formError = true
			} else if !u.Authenticate(password, []byte(conf.Auth.Secret)) {
				sess.SetFlash("form-error", "login-incorrect")
				formError = true
			} else {
				sess.Set(AuthUserKey, u)
				sess.Set(AuthNameKey, username)
			}

			if formError {
				http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
			} else {
				var returnPath string
				if v, ok := sess.Flash("return-to"); ok {
					returnPath = v.(string)
				} else {
					returnPath = webfw.GetDispatcher(c).Pattern
				}
				http.Redirect(w, r, returnPath, http.StatusTemporaryRedirect)
			}
			return
		}
		err := webfw.GetRenderCtx(c, r)(w, renderData, "login.tmpl")
		if err != nil {
			l.Print(err)
		}
	}
}
开发者ID:urandom,项目名称:readeef,代码行数:52,代码来源:login.go

示例11: Handler

func (con Login) Handler(c context.Context) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		l := webfw.GetLogger(c)
		sess := webfw.GetSession(c, r)
		data := renderer.RenderData{}

		if r.Method == "GET" {
			if v, ok := sess.Flash("form-error"); ok {
				data["form-error"] = v
			}
		} else {
			if err := r.ParseForm(); err != nil {
				l.Fatal(err)
			}
			username := r.Form.Get("username")
			password := r.Form.Get("password")

			db := GetDB(c)

			formError := false
			if u, err := db.GetUser(username); err != nil {
				sess.SetFlash("form-error", "login-incorrect")
				formError = true
			} else if !u.Authenticate(password) {
				sess.SetFlash("form-error", "login-incorrect")
				formError = true
			} else {
				sess.Set(authkey, u)
				sess.Set(namekey, u.Login)
			}

			if formError {
				http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
			} else {
				var returnPath string
				if v, ok := sess.Flash("return-to"); ok {
					returnPath = v.(string)
				} else {
					returnPath = webfw.GetDispatcher(c).Pattern
				}
				http.Redirect(w, r, returnPath, http.StatusTemporaryRedirect)
			}
			return
		}
		err := webfw.GetRenderCtx(c, r)(w, data, "login.tmpl")
		if err != nil {
			l.Print(err)
		}
	}
}
开发者ID:yourchanges,项目名称:readeef,代码行数:50,代码来源:login.go

示例12: Handler

func (con Component) Handler(c context.Context) http.HandlerFunc {
	rnd := renderer.NewRenderer(con.dir, "raw.tmpl")
	rnd.Delims("{%", "%}")

	return func(w http.ResponseWriter, r *http.Request) {
		params := webfw.GetParams(c, r)

		err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern},
			c.GetAll(r), "components/"+params["name"]+".tmpl")

		if err != nil {
			webfw.GetLogger(c).Print(err)
		}
	}
}
开发者ID:yourchanges,项目名称:readeef,代码行数:15,代码来源:component.go

示例13: Handler

func (con Auth) Handler(c context.Context) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user := readeef.GetUser(c, r)

		resp := getAuthData(user)

		b, err := json.Marshal(resp.val)
		if err != nil {
			webfw.GetLogger(c).Print(err)

			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		w.Write(b)
	})
}
开发者ID:RavenB,项目名称:readeef,代码行数:17,代码来源:auth.go

示例14: Handler

func (con App) Handler(c context.Context) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		rnd := webfw.GetRenderer(c)
		action := webfw.GetMultiPatternIdentifier(c, r)

		data := renderer.RenderData{}
		if action == "history" {
			params := webfw.GetParams(c, r)
			data["history"] = "/web/" + params["history"]
		}

		err := rnd.Render(w, data, c.GetAll(r), "app.tmpl")
		if err != nil {
			webfw.GetLogger(c).Print(err)
		}
	})
}
开发者ID:RavenB,项目名称:readeef,代码行数:17,代码来源:app.go

示例15: Handler

func (con Nonce) Handler(c context.Context) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		nonce := con.nonce.Generate()
		type response struct {
			Nonce string
		}
		resp := response{nonce}

		b, err := json.Marshal(resp)
		if err != nil {
			webfw.GetLogger(c).Print(err)

			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		w.Write(b)

		con.nonce.Set(nonce)
	})
}
开发者ID:urandom,项目名称:readeef,代码行数:21,代码来源:nonce.go


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