本文整理匯總了Golang中github.com/dvirsky/go-pylog/logging.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Get
//http get to the given ressource
func (t *Townclient) Get(sUrl string) (*http.Response, error) {
if strings.Contains(sUrl, "jpg") || strings.Contains(sUrl, "png") || strings.Contains(sUrl, "gif") || strings.Contains(sUrl, "jpeg") {
} else {
log.Info("%s[GET] url: %v", TAG, sUrl)
}
client := &http.Client{}
req, err := http.NewRequest("GET", sUrl, nil)
if err != nil {
log.Error("%s couldn't create Request to: %v", TAG, sUrl)
return nil, err
}
t.addHeader(req)
if t.cookies != nil {
for _, cookie := range t.cookies {
req.AddCookie(cookie)
}
}
time1 := time.Now()
t.dumpRequest(req, "town_get_req_"+strconv.Itoa(time1.Nanosecond()))
//connect to sUrl
resp, err := client.Do(req)
if err != nil {
log.Error("%s couldn't connect to: %v", TAG, sUrl)
return nil, err
}
t.dumpResponse(resp, "town_get_resp_"+strconv.Itoa(time1.Nanosecond()))
return resp, nil
}
示例2: ReadConfigs
func ReadConfigs() error {
if err := autoflag.Load(gofigure.DefaultLoader, &Config); err != nil {
logging.Error("Error loading configs: %v", err)
return err
}
logging.Info("Read configs: %#v", &Config)
for k, m := range Config.APIConfigs {
if conf, found := Config.apiconfs[k]; found && conf != nil {
b, err := yaml.Marshal(m)
if err == nil {
if err := yaml.Unmarshal(b, conf); err != nil {
logging.Error("Error reading config for API %s: %s", k, err)
} else {
logging.Debug("Unmarshaled API config for %s: %#v", k, conf)
}
} else {
logging.Error("Error marshalling config for API %s: %s", k, err)
}
} else {
logging.Warning("API Section %s in config file not registered with server", k)
}
}
return nil
}
示例3: Start
func (t *Townmanager) Start() {
t.page = 1
t.end = false
tc := &Townclient{}
tc.User = t.User
tc.Password = t.Password
err := t.init(tc)
log.Info("%s init finished, starting to parse...", TAG)
if err != nil {
log.Error("%s init failed", TAG)
log.Error("%s %s", TAG, err.Error())
return
}
tp := &Townparser{Url: t.url, Tc: tc}
count, err := tp.ParsePageCount()
if err != nil {
log.Error("%s %s", TAG, err.Error())
return
}
t.maxpage = count
log.Info("%s crawling approximately %v pages", TAG, t.maxpage)
t.saveReleases(tp.Rel)
i := 1
for {
if i == 1 {
err = tp.ParseReleases(false)
if err != nil {
log.Error("%s %s", TAG, err.Error())
break
}
} else {
tp = nil
tp = &Townparser{Url: t.url + "&pp=25&page=" + strconv.Itoa(i), Tc: tc}
err = tp.ParseReleases(true)
if err != nil {
log.Error("%s %s", TAG, err.Error())
break
}
}
log.Info("%s crawled page %v/%v", TAG, i, t.maxpage)
t.saveReleases(tp.Rel)
time.Sleep(5 * time.Second)
i++
if i == t.maxpage+1 {
break
}
if t.end {
log.Info("%s found old end point", TAG)
break
}
}
log.Info("%s parser closing", TAG)
}
示例4: Start
func (r *Runner) Start() {
go func() {
timeout := time.Second * 1
for {
select {
case <-time.After(timeout):
if !r.checkTown() {
timeout = time.Minute * 5
log.Info("town: trying login again in %v minute", timeout)
} else {
tm := town.Townmanager{User: r.Server.Config2.TownName, Password: r.Server.Config2.TownPassword, DB: r.Server.RelDB}
go tm.Start()
dur, err := time.ParseDuration(r.Server.Config2.Timeout)
if err != nil {
log.Error(err.Error())
}
c := time.Tick(dur)
for _ = range c {
log.Info("tick start town")
go tm.Start()
}
}
}
break
}
return
}()
go func() {
timeout := time.Second * 2
for {
select {
case <-time.After(timeout):
if !r.checkTown() {
timeout = time.Minute * 5
log.Info("ghost: trying to login again in %v minute", timeout)
} else {
gm := ghost.Ghostmanager{User: r.Server.Config2.GhostName, Password: r.Server.Config2.GhostPassword, DB: r.Server.RelDB}
go gm.Start()
dur, err := time.ParseDuration(r.Server.Config2.Timeout)
if err != nil {
log.Error(err.Error())
}
c := time.Tick(dur)
for _ = range c {
log.Info("tick start ghost")
go gm.Start()
}
}
}
break
}
return
}()
}
示例5: Start
func (g *Ghostmanager) Start() {
g.end = false
gc := &Ghostclient{}
gc.User = g.User
gc.Password = g.Password
err := g.init(gc)
log.Info("%s init finished, starting to parse...", TAG)
if err != nil {
log.Error("%s init failed", TAG)
log.Error("%s %s", TAG, err.Error())
return
}
tp := &Ghostparser{Url: g.url, Gc: gc}
i := 1
for {
if i == 1 {
err = tp.ParseReleases()
if err != nil {
log.Error("%s %s", TAG, err.Error())
break
}
g.maxpage = tp.Count
log.Info("%s crawling approximately %v pages", TAG, g.maxpage)
} else {
tp = nil
tp = &Ghostparser{Url: g.url + "&page=" + strconv.Itoa(i), Gc: gc}
err = tp.ParseReleases()
if err != nil {
log.Error("%s %s", TAG, err.Error())
break
}
}
g.saveReleases(tp.Rel)
log.Info("%s crawled page %v/%v", TAG, i, g.maxpage)
time.Sleep(5 * time.Second)
i++
if i == g.maxpage+1 {
break
}
if g.end {
log.Info("%s found old end point", TAG)
break
}
}
log.Info("%s closing", TAG)
}
示例6: GetLogs
func GetLogs(server *Server, parms martini.Params) string {
offset, _ := strconv.Atoi(parms["offset"])
var all []mydb.Log
_, err := server.LogDB.Select(&all, "select * from log ORDER BY id DESC LIMIT 50 OFFSET ?", offset)
if err != nil {
log.Error(err.Error())
}
by, err := json.Marshal(all)
if err != nil {
log.Error(err.Error())
}
return string(by)
}
示例7: parseInput
// Parse the user input into a request handler struct, with input validation
func parseInput(r *http.Request, input interface{}, validator *RequestValidator) error {
schemaDecoder.IgnoreUnknownKeys(true)
if err := r.ParseForm(); err != nil {
return InvalidRequestError("Error parsing request data: %s", err)
}
// We do not map and validate input to non-struct handlers
if reflect.TypeOf(input).Kind() != reflect.Func {
if err := schemaDecoder.Decode(input, r.Form); err != nil {
return InvalidRequestError("Error decoding schema: %s", err)
}
// Validate the input based on the API spec
if err := validator.Validate(input, r); err != nil {
logging.Error("Error validating http.Request!: %s", err)
return NewError(err)
}
}
return nil
}
示例8: Validate
func (rv *RequestValidator) Validate(request interface{}, r *http.Request) error {
val := reflect.ValueOf(request)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
//go over all the validators
for _, v := range rv.fieldValidators {
// find the field in the struct. we assume it's there since we build the validators on start time
field := val.FieldByName(v.GetKey())
// if the arg is optional and not set, we set the default
if v.IsOptional() && (!field.IsValid() || r.FormValue(v.GetParamName()) == "") {
def, ok := v.GetDefault()
if ok {
logging.Info("Default value for %s: %v", v.GetKey(), def)
field.Set(reflect.ValueOf(def).Convert(field.Type()))
}
}
// now we validate!
e := v.Validate(field, r)
if e != nil {
logging.Error("Could not validate field %s: %s", v.GetParamName(), e)
return e
}
}
return nil
}
示例9: getSValue
func (t *Townclient) getSValue() (sValue string) {
log.Info("%s getting sValue for town login", TAG)
sValue = ""
var doc *goquery.Document
var e error
log.Info("%s[GET] url: %v", TAG, ROOT)
if doc, e = goquery.NewDocument(ROOT); e != nil {
log.Error("%s %s", TAG, e.Error())
return
}
doc.Find("input").Each(func(i int, s *goquery.Selection) {
attr, exists := s.Attr("name")
if exists == true {
if attr == "s" {
bla, exists := s.Attr("value")
if exists == true {
sValue = bla
}
}
}
})
log.Info("%s sValue: %v", TAG, sValue)
return sValue
}
示例10: SetRating
func SetRating(server *Server, parms martini.Params) string {
checksum := parms["checksum"]
score, _ := strconv.Atoi(parms["score"])
rating, err := server.RelDB.SelectInt("select rating from release where checksum=?", checksum)
if err != nil {
log.Error(err.Error())
}
oldrating := rating
rating += int64(score)
log.Info("changing score for %s from %v to %v", checksum, oldrating, rating)
_, err = server.RelDB.Exec("update release set rating=? where checksum=?", rating, checksum)
if err != nil {
log.Error(err.Error())
}
return fmt.Sprintf("%v %v", checksum, score)
}
示例11: LinkFollow
func LinkFollow(w http.ResponseWriter, r *http.Request, server *Server, parms martini.Params) {
checksum := parms["checksum"]
hits, err := server.RelDB.SelectInt("select hits from release where checksum=?", checksum)
if err != nil {
log.Error(err.Error())
}
oldhits := hits
hits += 1
log.Info("increasing hits for %s from %v to %v", checksum, oldhits, hits)
_, err = server.RelDB.Exec("update release set hits=? where checksum=?", hits, checksum)
if err != nil {
log.Error(err.Error())
}
url, err := server.RelDB.SelectStr("select url from release where checksum=?", checksum)
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
}
示例12: EncodeToken
func (j *JWTAuthenticator) EncodeToken(data interface{}) (string, error) {
token := jwt.New(jwt.SigningMethodHS256)
token.Claims["data"] = data
sstr, err := token.SignedString(j.key)
if err != nil {
logging.Error("Error signing token: %s", err)
}
return sstr, err
}
示例13: getBoardId
func (g *Ghostparser) getBoardId(str string) int {
regex, err := regexp.Compile("boardid=.+&")
if err != nil {
log.Error("%s %s", TAG, err.Error())
return -1
}
str = regex.FindString(str)
str = strings.Replace(str, "&", "", -1)
astr := strings.Split(str, "=")
if len(astr) < 2 {
return -1
}
i, err := strconv.Atoi(astr[1])
if err != nil {
log.Error("%s %s", TAG, err.Error())
return -1
}
return i
}
示例14: middlewareHandler
func (a *API) middlewareHandler(chain *step, security SecurityScheme, renderer Renderer) func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
// allow overriding the API's default renderer with a per-route one
if renderer == nil {
renderer = a.Renderer
}
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
req := NewRequest(r)
if !a.AllowInsecure && !req.Secure {
// local requests bypass security
if req.RemoteIP != "127.0.0.1" {
http.Error(w, insecureAccessMessage, http.StatusForbidden)
return
}
}
r.ParseForm()
// Copy values from the router params to the request params
for _, v := range p {
r.Form.Set(v.Key, v.Value)
}
var ret interface{}
var err error
if security != nil {
if err = security.Validate(req); err != nil {
logging.Warning("Error validating security scheme: %s", err)
if e, ok := err.(*internalError); ok {
e.Code = ErrUnauthorized
err = e
}
}
}
if err == nil {
ret, err = chain.handle(w, req)
}
if err != Hijacked {
if err = renderer.Render(ret, err, w, req); err != nil {
logging.Error("Error rendering response: %s", err)
}
} else {
logging.Debug("Not rendering hijacked request %s", r.RequestURI)
}
}
}
示例15: configure
// configure registers the API's routes on a router. If the passed router is nil, we create a new one and return it.
// The nil mode is used when an API is run in stand-alone mode.
func (a *API) configure(router *httprouter.Router) *httprouter.Router {
if router == nil {
router = httprouter.New()
}
for i, route := range a.Routes {
if err := route.parseInfo(route.Path); err != nil {
logging.Error("Error parsing info for %s: %s", route.Path, err)
}
a.Routes[i] = route
h := a.handler(route)
pth := a.FullPath(route.Path)
if route.Methods&GET == GET {
logging.Info("Registering GET handler %v to path %s", h, pth)
router.Handle("GET", pth, h)
}
if route.Methods&POST == POST {
logging.Info("Registering POST handler %v to path %s", h, pth)
router.Handle("POST", pth, h)
}
}
chain := buildChain(a.SwaggerMiddleware...)
if chain == nil {
chain = buildChain(a.swaggerHandler())
} else {
chain.append(a.swaggerHandler())
}
// Server the API documentation swagger
router.GET(a.FullPath("/swagger"), a.middlewareHandler(chain, nil, nil))
chain = buildChain(a.TestMiddleware...)
if chain == nil {
chain = buildChain(a.testHandler())
} else {
chain.append(a.testHandler())
}
router.GET(path.Join("/test", a.root(), ":category"), a.middlewareHandler(chain, nil, nil))
// Redirect /$api/$version/console => /console?url=/$api/$version/swagger
uiPath := fmt.Sprintf("/console?url=%s", url.QueryEscape(a.FullPath("/swagger")))
router.Handler("GET", a.FullPath("/console"), http.RedirectHandler(uiPath, 301))
return router
}