Giter VIP home page Giter VIP logo

goboot's Introduction

In Chinese 中文版

goboot

Inspired by springboot framework, making it easy to create web application with go.

Features

  • simple, easy to use
  • high performance(try to not use reflection)
  • request log (in access_log.go) and response log (in response_log.go)
  • request/response log skip by api path
  • trace every http request and response in controller, service and dao by trace id
  • log files classified to default.log and error.log
  • log desensitization

Usage

http response

{
    "code":0,
    "message":"Success",
    "data":{
        "Id":1,"Name":"Ray","Age":6,"Address":"123","Modified":"2022-05-29T14:13:01+08:00","Created":"2022-05-29T14:13:01+08:00"
    },
    "details":[],
    "traceId":"n82gede29h"
}
  • Use the value of 'traceId'("n82gede29h") in the rest api response, you can quickly find the root cause from the default.log or error.log
  • You just need to do: grep 'n82gede29h' default.log (errro.log)

http request log

{"level":"info","ts":"2022-05-29T23:30:56.104+0800","caller":"middleware/access_log.go:43","msg":"AccessLog","Method":"POST","IP":"127.0.0.1","Path":"/v1/student/get_one","Header":{"Accept":["*/*"],"Accept-Encoding":["gzip, deflate, br"],"Cache-Control":["no-cache"],"Connection":["keep-alive"],"Content-Length":["22"],"Content-Type":["application/json"],"Postman-Token":["ded26fff-52e5-4fca-8d62-534bbd8c2a21"],"User-Agent":["PostmanRuntime/7.29.0"]},"Query":"","UserAgent":"PostmanRuntime/7.29.0","Request":"{\n    \"studentId\": 1\n}","TraceID":"n82gede29h"}

http response log

{"level":"info","ts":"2022-05-29T23:30:56.114+0800","caller":"middleware/response_log.go:51","msg":"ResponseLog","Status":200,"Path":"/v1/student/get_one","Response":"{\"code\":0,\"message\":\"Success\",\"data\":{\"Id\":1,\"Name\":\"Ray\",\"Age\":6,\"Address\":\"123\",\"Modified\":\"2022-05-29T14:13:01+08:00\",\"Created\":\"2022-05-29T14:13:01+08:00\"},\"details\":[],\"traceId\":\"n82gede29h\"}","Cost":0.010137309,"TraceID":"n82gede29h"}

all tracing log

{"level":"info","ts":"2022-05-29T23:30:56.104+0800","caller":"middleware/access_log.go:43","msg":"AccessLog","Method":"POST","IP":"127.0.0.1","Path":"/v1/student/get_one","Header":{"Accept":["*/*"],"Accept-Encoding":["gzip, deflate, br"],"Cache-Control":["no-cache"],"Connection":["keep-alive"],"Content-Length":["22"],"Content-Type":["application/json"],"Postman-Token":["ded26fff-52e5-4fca-8d62-534bbd8c2a21"],"User-Agent":["PostmanRuntime/7.29.0"]},"Query":"","UserAgent":"PostmanRuntime/7.29.0","Request":"{\n    \"studentId\": 1\n}","TraceID":"n82gede29h"}
{"level":"info","ts":"2022-05-29T23:30:56.114+0800","caller":"dao/student_dao.go:21","msg":"SqlInfoLog","elapsed":0.009854539,"rows":1,"sql":"SELECT * FROM `student` WHERE id =1 ","TraceID":"n82gede29h"}
{"level":"info","ts":"2022-05-29T23:30:56.114+0800","caller":"service/student_service.go:21","msg":"student=&{1 Ray 6 123 2022-05-29 14:13:01 +0800 CST 2022-05-29 14:13:01 +0800 CST}","TraceID":"n82gede29h"}
{"level":"debug","ts":"2022-05-29T23:30:56.114+0800","caller":"controller/student_controller.go:37","msg":"student=&{1 Ray 6 123 2022-05-29 14:13:01 +0800 CST 2022-05-29 14:13:01 +0800 CST}","TraceID":"n82gede29h"}
{"level":"info","ts":"2022-05-29T23:30:56.114+0800","caller":"middleware/response_log.go:51","msg":"ResponseLog","Status":200,"Path":"/v1/student/get_one","Response":"{\"code\":0,\"message\":\"Success\",\"data\":{\"Id\":1,\"Name\":\"Ray\",\"Age\":6,\"Address\":\"123\",\"Modified\":\"2022-05-29T14:13:01+08:00\",\"Created\":\"2022-05-29T14:13:01+08:00\"},\"details\":[],\"traceId\":\"n82gede29h\"}","Cost":0.010137309,"TraceID":"n82gede29h"}
  • One request has one trace path: access_log=>student_controller=>student_service=>student_dao=>response_log
  • You can also see all sql log with the 'TraceID', which will help to trace the database operation

goboot's People

Contributors

zxgangandy avatar

Watchers

 avatar

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.