Skip to content

ghinknet/payutils-http-echo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

payutils-http-echo

Echo HTTP driver for payutils.

Adapts an Echo router so payutils can register provider callback routes on it. Standard-library http.HandlerFuncs are bridged to Echo via echo.WrapHandler.

Module

go.gh.ink/payutils/http/echo/v3
go get go.gh.ink/payutils/http/echo/v3

Usage

Blank-import the driver (it self-registers under the name echo) and pass an Echo router (*echo.Echo or a route group) in Config.Instances:

import (
    "github.com/labstack/echo/v4"

    "go.gh.ink/payutils/v3/client"
    "go.gh.ink/payutils/v3/model"

    httpEcho "go.gh.ink/payutils/http/echo/v3"
    _ "go.gh.ink/payutils/pay/alipay/v3"
)

e := echo.New()

c, err := client.NewClient(model.Config{
    Endpoint:    "https://api.example.com",
    Instances:   model.I{httpEcho.Name: e}, // *echo.Echo or *echo.Group
    Credentials: model.C{ /* ... */ },
    Contract:    myContract{},
})

payutils then registers POST /{provider}/callback on the router for each configured provider.

Accepted instance

*echo.Echo and *echo.Group (both satisfy the driver's common router subset). Passing an unsupported value makes NewInstance return errors.ErrUnsupportedInstance.

Supported verbs

Get · Post · Put · Patch · Delete · Head · Options · Any.

License

See LICENSE.

About

Echo http driver for payutils

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages