Skip to content

[service] add raw service match go guideline #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions service/raw/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package raw

import "context"

// RawService is the interface that provides the business logic for the service.
type RawService[Req, Resp any] interface {
// RawCall is the entry point for the service.
RawCall(ctx context.Context, req Req) (Resp, error)
}

// RawServiceFn is the function type that implements the Service interface.
type RawServiceFn[Req, Resp any] func(context.Context, Req) (Resp, error)

func (self RawServiceFn[Req, Resp]) RawCall(ctx context.Context, req Req) (Resp, error) {
return self(ctx, req)
}

type RawLayer[Req, Resp any, S RawService[Req, Resp]] interface {
RawNext(service S) S
}

type RawLayerFn[Req, Resp any, S RawService[Req, Resp]] func(service S) S

func (self RawLayerFn[Req, Resp, S]) RawNext(service S) S { return self(service) }

func ComposeRawLayers[Req, Resp any, S RawService[Req, Resp], L RawLayer[Req, Resp, S]](service S, layers ...L) S {
for _, layer := range layers {
service = layer.RawNext(service)
}
return service
}