Compare commits

..

7 Commits

Author SHA1 Message Date
vtolstov
7a79159c39 Apply Code Coverage Badge 2025-06-11 06:44:09 +00:00
pugnack
c37081ec19 add missing outgoing key to ctx for subscribers (#224) 2025-06-11 09:37:55 +03:00
pugnack
3ab7c5cc29 update ci (#219) 2025-05-05 19:19:28 +03:00
pugnack
13feeefa42 [v3] update ci (#217)
* update ci

* disable coverage job
2025-05-03 10:44:46 +03:00
pugnack
ea3b2e5f4c [v3] rename .gitea to .github (#215)
* rename .gitea to .github

* attempt to fix lint job

* attempt to fix test job

* attempt to fix lint/test job
2025-04-28 09:52:19 +03:00
707476bbd4 Merge pull request 'update for latest micro' (#198) from register into v3
Some checks failed
test / test (push) Failing after 2m25s
Reviewed-on: #198
2024-12-27 01:56:50 +03:00
228251bc55 v3 (#197)
Some checks failed
test / test (push) Has been cancelled
## Pull Request template
Please, go through these steps before clicking submit on this PR.

1. Give a descriptive title to your PR.
2. Provide a description of your changes.
3. Make sure you have some relevant tests.
4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable).

**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**

Reviewed-on: #197
Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru>
Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
2024-12-27 01:56:04 +03:00
15 changed files with 89 additions and 39 deletions

53
.github/workflows/job_coverage.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
name: coverage
on:
push:
branches: [ main, v3, v4 ]
paths-ignore:
- '.github/**'
- '.gitea/**'
pull_request:
branches: [ main, v3, v4 ]
jobs:
build:
if: github.server_url != 'https://github.com'
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
with:
filter: 'blob:none'
- name: setup go
uses: actions/setup-go@v5
with:
cache-dependency-path: "**/*.sum"
go-version: 'stable'
- name: test coverage
run: |
go test -v -cover ./... -covermode=count -coverprofile coverage.out -coverpkg ./...
go tool cover -func coverage.out -o coverage.out
- name: coverage badge
uses: tj-actions/coverage-badge-go@v2
with:
green: 80
filename: coverage.out
- uses: stefanzweifel/git-auto-commit-action@v4
name: autocommit
with:
commit_message: Apply Code Coverage Badge
skip_fetch: false
skip_checkout: false
file_pattern: ./README.md
- name: push
if: steps.auto-commit-action.outputs.changes_detected == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ github.token }}
branch: ${{ github.ref }}

View File

@@ -3,10 +3,10 @@ name: lint
on: on:
pull_request: pull_request:
types: [opened, reopened, synchronize] types: [opened, reopened, synchronize]
branches: branches: [ master, v3, v4 ]
- master paths-ignore:
- v3 - '.github/**'
- v4 - '.gitea/**'
jobs: jobs:
lint: lint:
@@ -20,10 +20,10 @@ jobs:
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
cache-dependency-path: "**/*.sum" cache-dependency-path: "**/*.sum"
go-version: 'stable' go-version: 'stable'
- name: setup deps - name: setup deps
run: go get -v ./... run: go get -v ./...
- name: run lint - name: run lint
uses: https://github.com/golangci/golangci-lint-action@v6 uses: golangci/golangci-lint-action@v6
with: with:
version: 'latest' version: 'latest'

View File

@@ -3,15 +3,12 @@ name: test
on: on:
pull_request: pull_request:
types: [opened, reopened, synchronize] types: [opened, reopened, synchronize]
branches: branches: [ master, v3, v4 ]
- master
- v3
- v4
push: push:
branches: branches: [ master, v3, v4 ]
- master paths-ignore:
- v3 - '.github/**'
- v4 - '.gitea/**'
jobs: jobs:
test: test:

View File

@@ -3,15 +3,12 @@ name: test
on: on:
pull_request: pull_request:
types: [opened, reopened, synchronize] types: [opened, reopened, synchronize]
branches: branches: [ master, v3, v4 ]
- master
- v3
- v4
push: push:
branches: branches: [ master, v3, v4 ]
- master paths-ignore:
- v3 - '.github/**'
- v4 - '.gitea/**'
jobs: jobs:
test: test:
@@ -35,19 +32,19 @@ jobs:
go-version: 'stable' go-version: 'stable'
- name: setup go work - name: setup go work
env: env:
GOWORK: /workspace/${{ github.repository_owner }}/go.work GOWORK: ${{ github.workspace }}/go.work
run: | run: |
go work init go work init
go work use . go work use .
go work use micro-tests go work use micro-tests
- name: setup deps - name: setup deps
env: env:
GOWORK: /workspace/${{ github.repository_owner }}/go.work GOWORK: ${{ github.workspace }}/go.work
run: go get -v ./... run: go get -v ./...
- name: run tests - name: run tests
env: env:
INTEGRATION_TESTS: yes INTEGRATION_TESTS: yes
GOWORK: /workspace/${{ github.repository_owner }}/go.work GOWORK: ${{ github.workspace }}/go.work
run: | run: |
cd micro-tests cd micro-tests
go test -mod readonly -v ./... || true go test -mod readonly -v ./... || true

View File

@@ -1,5 +1,5 @@
run: run:
concurrency: 8 concurrency: 8
deadline: 5m timeout: 5m
issues-exit-code: 1 issues-exit-code: 1
tests: true tests: true

View File

@@ -1,4 +1,5 @@
# HTTP Server # HTTP Server
![Coverage](https://img.shields.io/badge/Coverage-2.5%25-red)
The HTTP Server is a go-micro.Server. It's a partial implementation which strips out codecs, transports, etc but enables you The HTTP Server is a go-micro.Server. It's a partial implementation which strips out codecs, transports, etc but enables you
to create a HTTP Server that could potentially be used for REST based API services. to create a HTTP Server that could potentially be used for REST based API services.

5
go.mod
View File

@@ -1,13 +1,14 @@
module go.unistack.org/micro-server-http/v3 module go.unistack.org/micro-server-http/v3
go 1.22.0 go 1.22.2
toolchain go1.24.2
require ( require (
go.unistack.org/micro-client-http/v3 v3.9.15 go.unistack.org/micro-client-http/v3 v3.9.15
go.unistack.org/micro-codec-yaml/v3 v3.10.3 go.unistack.org/micro-codec-yaml/v3 v3.10.3
go.unistack.org/micro-proto/v3 v3.4.1 go.unistack.org/micro-proto/v3 v3.4.1
go.unistack.org/micro/v3 v3.11.30 go.unistack.org/micro/v3 v3.11.41
golang.org/x/net v0.33.0 golang.org/x/net v0.33.0
) )

4
go.sum
View File

@@ -878,8 +878,8 @@ go.unistack.org/micro-codec-yaml/v3 v3.10.3 h1:H0jM4wCSReHzEc1hnKYgXjzg171+tUE6I
go.unistack.org/micro-codec-yaml/v3 v3.10.3/go.mod h1:pruYGvCULoHa6Tfah1UnTrwCzQhy0KT6D4UXEMgf+tk= go.unistack.org/micro-codec-yaml/v3 v3.10.3/go.mod h1:pruYGvCULoHa6Tfah1UnTrwCzQhy0KT6D4UXEMgf+tk=
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q= go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo= go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
go.unistack.org/micro/v3 v3.11.30 h1:XTLgZubSGzQL85IUMp1pTJnS1lP4eFwTZyelV/SzOMc= go.unistack.org/micro/v3 v3.11.41 h1:dP4sBLIZpMo+MWGe5bbESewK8wBzYm4Yik/67x4dEtQ=
go.unistack.org/micro/v3 v3.11.30/go.mod h1:fvOkXKs3wKHToWH6Mxy+aovEiDl2q4UlOCdVfJdziBU= go.unistack.org/micro/v3 v3.11.41/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

View File

@@ -127,6 +127,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
} }
ctx = metadata.NewIncomingContext(ctx, md) ctx = metadata.NewIncomingContext(ctx, md)
ctx = metadata.NewOutgoingContext(ctx, metadata.New(0))
path := r.URL.Path path := r.URL.Path
@@ -166,7 +167,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
hdlr := shdlr.(*httpHandler) hdlr := shdlr.(*httpHandler)
fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod) fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod)
if err == nil { if err == nil {
match = true // match = true
for k, v := range mp { for k, v := range mp {
matches[k] = v matches[k] = v
} }
@@ -272,7 +273,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
} }
// wrap the handler func // wrap the handler func
h.opts.Hooks.EachNext(func(hook options.Hook) { h.opts.Hooks.EachPrev(func(hook options.Hook) {
if h, ok := hook.(server.HookHandler); ok { if h, ok := hook.(server.HookHandler); ok {
fn = h(fn) fn = h(fn)
} }
@@ -583,6 +584,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Body != nil { if r.Body != nil {
var buf []byte var buf []byte
buf, err = io.ReadAll(r.Body) buf, err = io.ReadAll(r.Body)
r.Body.Close()
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError) h.errorHandler(ctx, handler, w, r, err, http.StatusInternalServerError)
return return
@@ -639,7 +641,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return err return err
} }
h.opts.Hooks.EachNext(func(hook options.Hook) { h.opts.Hooks.EachPrev(func(hook options.Hook) {
if h, ok := hook.(server.HookHandler); ok { if h, ok := hook.(server.HookHandler); ok {
fn = h(fn) fn = h(fn)
} }

View File

@@ -1,8 +1,6 @@
package http package http
import ( import (
"io"
"go.unistack.org/micro/v3/codec" "go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/metadata" "go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v3/server" "go.unistack.org/micro/v3/server"
@@ -14,7 +12,7 @@ var (
) )
type rpcRequest struct { type rpcRequest struct {
rw io.ReadWriter // rw io.ReadWriter
payload interface{} payload interface{}
codec codec.Codec codec codec.Codec
header metadata.Metadata header metadata.Metadata

View File

@@ -88,6 +88,7 @@ func (s *Server) createSubHandler(sb *httpSubscriber, opts server.Options) broke
hdr := metadata.Copy(msg.Header) hdr := metadata.Copy(msg.Header)
ctx := metadata.NewIncomingContext(context.Background(), hdr) ctx := metadata.NewIncomingContext(context.Background(), hdr)
ctx = metadata.NewOutgoingContext(ctx, metadata.New(0))
results := make(chan error, len(sb.handlers)) results := make(chan error, len(sb.handlers))
@@ -129,7 +130,7 @@ func (s *Server) createSubHandler(sb *httpSubscriber, opts server.Options) broke
return nil return nil
} }
opts.Hooks.EachNext(func(hook options.Hook) { opts.Hooks.EachPrev(func(hook options.Hook) {
if h, ok := hook.(server.HookSubHandler); ok { if h, ok := hook.(server.HookSubHandler); ok {
fn = h(fn) fn = h(fn)
} }