偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

常用的 Git 配置,你知道幾個?

開發(fā) 前端
OTel 是可觀測系統(tǒng)的新標準,基于它可以兼容以前使用的 Prometheus、 victoriametrics、skywalking 等系統(tǒng),同時還可以靈活擴展,不用與任何但一生態(tài)或技術(shù)棧進行綁定。
  1. 使用NewServer函數(shù)構(gòu)建服務(wù)實例,利用依賴注入方式將所有的依賴參數(shù)包含進來。
func NewServer(
 logger *Logger
 config *Config
 commentStore *commentStore
 anotherStore *anotherStore
) http.Handler {
 mux := http.NewServeMux()
 addRoutes(
  mux,
  Logger,
  Config,
  commentStore,
  anotherStore,
 )
 var handler http.Handler = mux
 handler = someMiddleware(handler)
 handler = someMiddleware2(handler)
 handler = someMiddleware3(handler)
 return handler
}
  1. 在routes.go文件中統(tǒng)一定義所有路由函數(shù)。
func addRoutes(
 mux                 *http.ServeMux,
 logger              *logging.Logger,
 config              Config,
 tenantsStore        *TenantsStore,
 commentsStore       *CommentsStore,
 conversationService *ConversationService,
 chatGPTService      *ChatGPTService,
 authProxy           *authProxy
) {
 mux.Handle("/api/v1/", handleTenantsGet(logger, tenantsStore))
 mux.Handle("/oauth2/", handleOAuth2Proxy(logger, authProxy))
 mux.HandleFunc("/healthz", handleHealthzPlease(logger))
 mux.Handle("/", http.NotFoundHandler())
}
  1. 主函數(shù)只調(diào)用run函數(shù)來運行服務(wù)
func run(ctx context.Context, w io.Writer, args []string) error {
 ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
 defer cancel()

 // ...
}

func main() {
 ctx := context.Background()
 if err := run(ctx, os.Stdout, os.Args); err != nil {
  fmt.Fprintf(os.Stderr, "%s\n", err)
  os.Exit(1)
 }
}
  1. 返回閉包 handle
// handleSomething handles one of those web requests
// that you hear so much about.
func handleSomething(logger *Logger) http.Handler {
 thing := prepareThing()
 return http.HandlerFunc(
  func(w http.ResponseWriter, r *http.Request) {
   // use thing to handle request
   logger.Info(r.Context(), "msg", "handleSomething")
  }
 )
}
  1. 定義通用的encode和decode函數(shù)
func encode[T any](w http.ResponseWriter, r *http.Request, status int, v T) error {
 w.Header().Set("Content-Type", "application/json")
 w.WriteHeader(status)
 if err := json.NewEncoder(w).Encode(v); err != nil {
  return fmt.Errorf("encode json: %w", err)
 }
 return nil
}

func decode[T any](r *http.Request) (T, error) {
 var v T
 if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
  return v, fmt.Errorf("decode json: %w", err)
 }
 return v, nil
}
  1. 提供一個抽象的 Validator 接口用于驗證
// Validator is an object that can be validated.
type Validator interface {
 // Valid checks the object and returns any
 // problems. If len(problems) == 0 then
 // the object is valid.
 Valid(ctx context.Context) (problems map[string]string)
}

func decodeValid[T Validator](r *http.Request) (T, map[string]string, error) {
 var v T
 if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
  return v, nil, fmt.Errorf("decode json: %w", err)
 }
 if problems := v.Valid(r.Context()); len(problems) > 0 {
  return v, problems, fmt.Errorf("invalid %T: %d problems", v, len(problems))
 }
 return v, nil, nil
}

自定義校驗需要實現(xiàn) Validator 接口。

7.使用 Once 延遲調(diào)用來提高啟動性能。

func handleTemplate(files string...) http.HandlerFunc {
 var (
  init    sync.Once
  tpl     *template.Template
  tplerr  error
 )
 return func(w http.ResponseWriter, r *http.Request) {
  init.Do(func(){
   tpl, tplerr = template.ParseFiles(files...)
  })
  if tplerr != nil {
   http.Error(w, tplerr.Error(), http.StatusInternalServerError)
   return
  }
  // use tpl
 }
}

What is OpenTelemetry?

這是一篇 OTel 的科普文章

OpenTelemetry 提供一個統(tǒng)一、可擴展的框架,用于收集、分析和觀察分布式系統(tǒng)的性能數(shù)據(jù)。它包括一組API、庫、代理和收集器,這些組件可以跨多種編程語言和平臺實現(xiàn)對應(yīng)用程序的監(jiān)控。

OpenTelemetry 整合 OpenTracing 和 OpenCensus。

2019年,兩個社區(qū)進行了合并。

同時 OTel 具備以下特征:

  1. 統(tǒng)一性:OpenTelemetry 提供了一個統(tǒng)一的API,使得開發(fā)者可以在不同的編程語言和框架中以一致的方式實現(xiàn)監(jiān)控。
  2. 可擴展性:可以編寫自己的擴展來滿足個性化需要
  3. 跨平臺:OpenTelemetry 支持多種編程語言,如 Java、Python、Go、.NET 等,以及多種云服務(wù)和容器平臺。
  4. 社區(qū)驅(qū)動:作為一個開源項目,OpenTelemetry 由一個活躍的社區(qū)支持,社區(qū)成員貢獻代碼、文檔和最佳實踐。
  5. 與現(xiàn)有工具的兼容性:OpenTelemetry 設(shè)計時考慮了與現(xiàn)有監(jiān)控工具的兼容性,如 Prometheus、Jaeger、Zipkin 等,這使得它可以輕松地集成到現(xiàn)有的監(jiān)控基礎(chǔ)設(shè)施中。

提供了一種名為:OTLP(OpenTelemetry Protocol)的通訊協(xié)議,基于 gRPC。

使用該協(xié)議用于客戶端與 Collector 采集器進行交互。

Collector 是 OpenTelemetry 架構(gòu)中的一個關(guān)鍵組件,它負責(zé)接收、處理和導(dǎo)出數(shù)據(jù)(Trace/log/metrics)。

它可以接受從客戶端發(fā)出的數(shù)據(jù)進行處理,同時可以導(dǎo)出為不同格式的數(shù)據(jù)。

總的來說 OTel 是可觀測系統(tǒng)的新標準,基于它可以兼容以前使用的 Prometheus、 victoriametrics、skywalking 等系統(tǒng),同時還可以靈活擴展,不用與任何但一生態(tài)或技術(shù)棧進行綁定。

Popular git config options

本文總結(jié)了一些常用的 git 配置

  1. pull.ff only 或 pull.rebase true:這兩個選項都可以避免在執(zhí)行g(shù)it pull時意外創(chuàng)建合并提交,特別是當(dāng)上游分支已經(jīng)發(fā)生了變化的時候。
  2. merge.conflictstyle diff3:這個選項使得合并沖突更易于閱讀,通過在沖突中顯示原始代碼版本,幫助用戶更好地解決沖突。
  3. rebase.autosquash true 和 rebase.autostash true:這些選項使得修改舊提交變得更容易,并且自動處理stash。
  4. push.default simple 或 push.default current:這些選項告訴git push自動推送當(dāng)前分支到同名的遠程分支。
  5. init.defaultBranch main:創(chuàng)建新倉庫時,默認創(chuàng)建main分支而不是master分支。
  6. commit.verbose true:在提交時顯示整個提交差異。
  7. rerere.enabled true:啟用rerere功能,自動解決沖突
  8. help.autocorrect:設(shè)置自動矯正的級別,以自動運行建議的命令。
  9. core.pager delta:設(shè)置Git使用的分頁器,例如使用delta來查看帶有語法高亮的diff。
  10. diff.algorithm histogram:設(shè)置Git的diff算法,以改善函數(shù)重排時的diff顯示。

文章鏈接:

責(zé)任編輯:武曉燕 來源: crossoverJie
相關(guān)推薦

2021-10-12 09:20:02

數(shù)據(jù)庫SQL腳本

2023-10-31 08:23:54

網(wǎng)絡(luò)命令Linux

2020-02-23 23:29:07

Python編程開發(fā)

2021-05-06 15:15:13

Python工具代碼

2019-03-05 11:22:17

操作系統(tǒng)調(diào)度算法

2024-11-05 08:13:49

python視覺OpenCV

2022-01-07 08:23:38

k8s AnnotationNginx

2023-10-30 18:00:00

Docker命令開源平臺

2022-06-30 08:31:54

排序函數(shù)SQL

2023-04-11 08:49:42

排序函數(shù)SQL

2025-03-25 10:49:13

2023-05-17 12:33:11

AI人工智能

2021-11-04 11:54:30

Linux內(nèi)存系統(tǒng)

2023-04-27 08:15:09

2024-01-18 00:16:07

2021-02-27 17:13:21

前端代碼邏輯

2023-11-30 07:37:49

MySQL函數(shù)

2019-11-27 10:27:22

程序員Git腳本語言

2023-05-30 14:54:17

Python循環(huán)語句工具

2023-11-26 00:26:00

點贊
收藏

51CTO技術(shù)棧公眾號