Skip to content

Commit

Permalink
Merge branch 'master' into feat/add_es_client
Browse files Browse the repository at this point in the history
  • Loading branch information
qloog committed Jun 26, 2023
2 parents 4988970 + a1dee97 commit d8a3d1e
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 91 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- feat(es): add elasticsearch client(v7)
- chore(cli): approve gen task command
- chore(response): remove init resp and improve Error
- chore(server): improve consumer server

## v1.7.0
- feat(http): can custom http status
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
[![gitmoji](https://img.shields.io/badge/gitmoji-%20%F0%9F%98%9C%20%F0%9F%98%8D-FFDD67.svg?style=flat-square)](https://github.com/carloscuesta/gitmoji)
[![License](https://img.shields.io/github/license/go-eagle/eagle?style=flat-square)](/LICENSE)

## Introduction

A Go framework suitable for rapid business development, which can quickly build API services or Web sites.
A Go framework suitable for rapid business development, which can quickly build API services or Web sites.
English | [中文文档](https://github.com/go-eagle/eagle/blob/master/README_ZH.md)

## Features

Expand Down
6 changes: 4 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

一款适合于快速开发业务的 Go 框架,可快速构建 API 服务 或 Web 网站。

[English](https://github.com/go-eagle/eagle/blob/master/README.md) | 中文文档

## 官方文档

- 开发文档 [https://go-eagle.org/](https://go-eagle.org/)
Expand Down Expand Up @@ -148,8 +150,8 @@ eagle new github.com/foo/bar

## 📖 开发规约

- [配置说明](https://github.com/go-eagle/eagle/blob/master/conf)
- [错误码设计](https://github.com/go-eagle/eagle/tree/master/pkg/errno)
- [配置说明](https://github.com/go-eagle/eagle/blob/master/config)
- [错误码设计](https://github.com/go-eagle/eagle/tree/master/pkg/errcode)
- [service 的使用规则](https://github.com/go-eagle/eagle/blob/master/internal/service)
- [repository 的使用规则](https://github.com/go-eagle/eagle/blob/master/internal/repository)
- [cache 使用说明](https://github.com/go-eagle/eagle/blob/master/pkg/cache)
Expand Down
19 changes: 8 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ require (
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/pprof v1.3.0
github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e
github.com/gin-gonic/gin v1.7.7
github.com/gin-gonic/gin v1.9.0
github.com/go-kratos/aegis v0.1.1
github.com/go-mail/mail v2.3.1+incompatible
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.3 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.13.0
github.com/go-playground/universal-translator v0.17.0
github.com/go-playground/validator/v10 v10.4.1
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.11.2
github.com/go-redis/redis/extra/redisotel/v8 v8.10.0
github.com/go-redis/redis/v8 v8.11.2
github.com/go-sql-driver/mysql v1.5.0
Expand Down Expand Up @@ -64,7 +64,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.0
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.8.1
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.7.0 // indirect
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
Expand All @@ -87,15 +87,12 @@ require (
go.opentelemetry.io/otel/trace v1.3.0
go.uber.org/automaxprocs v1.5.1
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/tools v0.1.8 // indirect
golang.org/x/crypto v0.5.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1
google.golang.org/protobuf v1.28.1
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/mail.v2 v2.3.1 // indirect
gorm.io/driver/mysql v1.0.4
gorm.io/gorm v1.20.12
Expand Down
103 changes: 76 additions & 27 deletions go.sum

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions pkg/client/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ func doRequest(ctx context.Context, method, url string, payload []byte, opt *opt
req.Header.Set(key, value[0])
}

ctx, span := tracer.Start(req.Context(), fmt.Sprintf("HTTP %s", method))
defer span.End()

resp, err := client.Do(req)
if err != nil {
return nil, errors.Wrapf(err, "[httpClient] do request from [%s %s] err", method, url)
Expand Down
8 changes: 7 additions & 1 deletion pkg/errcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@
- 错误通常包括系统级错误码和服务级错误码
- 建议代码中按服务模块将错误分类
- 错误码均为 >= 0 的数
- 在本项目中 HTTP Code 固定为 http.StatusOK,错误码通过 code 来表示。
- 在本项目中 HTTP Code 固定为 http.StatusOK,错误码通过 code 来表示。


## Reference

- [gRPC错误处理](https://mp.weixin.qq.com/s/ghJiTvJxYzLKTFs5gZga5w)

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cronjob
package consumer

// ServerOption is cron server option.
type ServerOption func(o *Server)
Expand Down
66 changes: 66 additions & 0 deletions pkg/transport/consumer/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package consumer

import (
"context"
"time"

"github.com/pkg/errors"

"github.com/hibiken/asynq"
)

type Server struct {
clientOpt asynq.RedisClientOpt

// async server
srv *asynq.Server
mux *asynq.ServeMux

// async schedule
sche *asynq.Scheduler
}

func NewServer(redisOpt asynq.RedisClientOpt, asyncCfg asynq.Config) *Server {
srv := &Server{
srv: asynq.NewServer(redisOpt, asyncCfg),
mux: asynq.NewServeMux(),
sche: asynq.NewScheduler(
redisOpt,
&asynq.SchedulerOpts{Location: time.Local},
),
}

return srv
}

func (s *Server) Start(ctx context.Context) error {
go func() {
err := s.sche.Run()
if err != nil {
panic(err)
}
}()

err := s.srv.Run(s.mux)
if err != nil {
return errors.Wrapf(err, "failed to run async server: %v")
}

return nil
}

func (s *Server) Stop(ctx context.Context) error {
s.srv.Shutdown()
s.sche.Shutdown()
return nil
}

// RegisterTask register task
func (s *Server) RegisterTask(schedule string, task *asynq.Task) (entryID string, err error) {
return s.sche.Register(schedule, task)
}

// RegisterHandle register handler
func (s *Server) RegisterHandle(pattern string, handler func(context.Context, *asynq.Task) error) {
s.mux.HandleFunc(pattern, handler)
}
43 changes: 0 additions & 43 deletions pkg/transport/cronjob/server.go

This file was deleted.

0 comments on commit d8a3d1e

Please sign in to comment.