GithubHelp home page GithubHelp logo

ahlib-mx's Introduction

Introduction

Stars Earned Collaborated Stars Followers Repositories GitHub Page

  • ๐Ÿ‘‹ Hi! Here is AoiHosizora (้’ใ„ใปใ—ใžใ‚‰), majors in Intelligent Software and Robotics, Software Engineering.
  • ๐Ÿ“ Speaking languages: Mandarin Chinese (Native), Teo-Swa-uรช (Native), English (CET-6), Japanese (JLPT-N1).
  • ๐Ÿข Some owned GitHub organizations: ah-shellext & ah-forklib, my public email: [email protected].
  • ๐Ÿš€ Interest areas: distributed backend system development, desktop client and android client development.
  • โšก Favorite programming languages: Go, Dart, C#, Kotlin, Rust, Typescript, etc.

Coding status

ahlib-mx's People

Contributors

aoi-hosizora avatar

Watchers

 avatar

ahlib-mx's Issues

Adjust xdto and logger for recovery

  1. Add WithOthers for ErrorDto and remove BuildFullErrorDto.
  2. Move logger for recovery to xgin or xrecovery???
  3. Need to adjust result and add MarshalJSON to check run mode.

xtelebot logger alignment

	t.logger.WithFields(map[string]interface{}{
		"module":    "telebot",
		"messageID": m.ID,
		"endpoint":  ep,
		"chatID":    m.Chat.ID,
		"chatName":  m.Chat.Username,
	}).Info(fmt.Sprintf("[Telebot] %4d | -> | %14v | (%d %s)", m.ID, ep, m.Chat.ID, m.Chat.Username))

Align the loggers

Logger include: gin fiber | gorm redis neo4j | telebot serverchan

image

Add xtestweb

Add a xtestweb package to test http response just using the xtesting in ahlib.

Add a vararg interface{} parameter for xrecovery.WithExtraFields

https://github.com/Aoi-hosizora/ahlib-web/blob/8c048957fb02c28892672369e7f02f54cc8cc84c/xrecovery/logger.go#L18-L22

if err := recover(); err != nil {
	rid := c.Writer.Header().Get("X-Request-Id")
	r := result.Error(exception.ServerRecoveryError)
	r.Error = xgin.BuildErrorDto(err, c, skip, true, "request_id", rid)
	xrecovery.WithLogrus(logger, err, xrecovery.WithExtraString(rid), xrecovery.WithExtraFields(map[string]interface{}{"requestID": rid}))
	r.JSON(c)
}

xdto record

package xdto

import (
	"fmt"
	"github.com/Aoi-hosizora/ahlib-web/internal/xmap"
	"github.com/Aoi-hosizora/ahlib/xcolor"
	"github.com/Aoi-hosizora/ahlib/xruntime"
	"log"
	"os"
	"reflect"
	"time"
)

// ErrorDto is a general error response model.
type ErrorDto struct {
	Time    string   `json:"time"`    // current time
	Type    string   `json:"type"`    // error type
	Detail  string   `json:"detail"`  // error detail message
	Request []string `json:"request"` // request details

	Others map[string]interface{} `json:"others,omitempty"` // other message

	Filename  string   `json:"filename,omitempty"`   // stack filename
	Funcname  string   `json:"funcname,omitempty"`   // stack function name
	LineIndex int      `json:"line_index,omitempty"` // file line index
	Line      string   `json:"line,omitempty"`       // stack current line
	Stacks    []string `json:"stacks,omitempty"`     // stacks in skip
}

// BuildBasicErrorDto builds a basic dto (only include time, type, detail, request).
func BuildBasicErrorDto(err interface{}, requests []string, otherKvs ...interface{}) *ErrorDto {
	skip := -2
	return BuildErrorDto(err, requests, skip, false, otherKvs...)
}

// BuildErrorDto builds a complete dto (also include runtime parameters).
func BuildErrorDto(err interface{}, requests []string, skip int, doPrint bool, otherKvs ...interface{}) *ErrorDto {
	if err == nil {
		return nil
	}

	// basic
	now := time.Now().Format(time.RFC3339)
	errType := reflect.TypeOf(err).String()
	errDetail := ""
	if e, ok := err.(error); ok {
		errDetail = e.Error()
	} else {
		errDetail = fmt.Sprintf("%v", err)
	}
	if requests == nil {
		requests = []string{}
	}
	dto := &ErrorDto{Time: now, Type: errType, Detail: errDetail, Request: requests}

	// other
	dto.Others = xmap.SliceToStringMap(otherKvs)

	// runtime
	if skip >= 0 {
		skip++
		var stacks xruntime.TraceStack
		stacks, dto.Filename, dto.Funcname, dto.LineIndex, dto.Line = xruntime.RuntimeTraceStackWithInfo(skip)
		dto.Stacks = make([]string, len(stacks))
		for idx, stack := range stacks {
			dto.Stacks[idx] = stack.String()
		}
		if doPrint {
			l := log.New(os.Stderr, "", 0)
			l.Println()
			l.Println(xcolor.Red.Sprint(stacks.String()))
			l.Println()
		}
	}

	return dto
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.