Skip to content
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

Refactor server to use the Echo framework #26

Merged
merged 6 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export GOFLAGS=-mod=vendor

DOCKER_IMG ?= form3tech/pact-proxy

ifeq (${platform},Darwin)
ifeq (${PLATFORM},Darwin)
PACT_FILE := "pact-${PACT_VERSION}-osx.tar.gz"
else
PACT_FILE := "pact-${PACT_VERSION}-linux-x86_64.tar.gz"
Expand Down Expand Up @@ -41,7 +41,7 @@ vendor:
install-pact:
@if [ ! -d ./pact ]; then \
echo "pact not installed, installing..."; \
wget --quiet https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_VERSION}/${PACT_FILE} -O /tmp/pactserver.tar.gz && tar -xzf /tmp/pactserver.tar.gz 2>/dev/null -C .; \
curl -s https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_VERSION}/${PACT_FILE} -L -o /tmp/pactserver.tar.gz && tar -xzf /tmp/pactserver.tar.gz 2>/dev/null -C .; \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're changing this, can we do -sSLf

       -s, --silent
      -S, --show-error
              When used with -s, --silent, it makes curl show an error message if it fails.
       -L, --location
       -f, --fail

perhaps all the options directly after curl, rather it being in the middle? -o could remain where it is I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

fi

.PHONY: publish
Expand Down
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/PaesslerAG/jsonpath v0.1.1
github.com/avast/retry-go/v4 v4.1.0
github.com/labstack/echo/v4 v4.9.0
github.com/pact-foundation/pact-go v1.7.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
Expand All @@ -17,10 +18,18 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/go-version v1.5.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tidwall/gjson v1.12.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,19 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down Expand Up @@ -238,6 +246,10 @@ github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp1
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand All @@ -253,6 +265,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -289,6 +302,8 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -315,8 +330,11 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211107104306-e0b2ad06fe42/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -326,6 +344,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -400,6 +420,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
67 changes: 32 additions & 35 deletions internal/app/configuration/api.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
package configuration

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

"github.com/form3tech-oss/pact-proxy/internal/app/httpresponse"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
)

func ServeAdminAPI(port int) *http.Server {
adminServerHandler := http.NewServeMux()
s := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: adminServerHandler,
}
func ServeAdminAPI(port int) *echo.Echo {
adminServer := echo.New()
adminServer.HideBanner = true

adminServerHandler.HandleFunc("/proxies", adminHandler)
adminServer.DELETE("/proxies", deleteProxiesHandler)
adminServer.POST("/proxies", postProxiesHandler)

go func() {
if err := s.ListenAndServe(); err != nil {
address := fmt.Sprintf(":%d", port)
if err := adminServer.Start(address); err != nil {
log.Fatal(err)
}
}()

return s
return adminServer
}

func adminHandler(w http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodDelete {
log.Infof("closing all proxies")
CloseAllServers()
return
}
func deleteProxiesHandler(c echo.Context) error {
log.Infof("closing all proxies")
CloseAllServers()
return c.NoContent(http.StatusNoContent)
}

if req.Method == http.MethodPost {
configBytes, err := ioutil.ReadAll(req.Body)
if err != nil {
httpresponse.Errorf(w, http.StatusBadRequest, "unable to read constraint. %s", err.Error())
return
}
func postProxiesHandler(c echo.Context) error {

proxyConfig := ProxyConfig{}
err = json.Unmarshal(configBytes, &proxyConfig)
if err != nil {
httpresponse.Errorf(w, http.StatusBadRequest, "unable to parse interactionConstraint from data. %s", err.Error())
return
}
proxyConfig := ProxyConfig{}
err := c.Bind(&proxyConfig)
if err != nil {
return c.JSON(
http.StatusBadRequest,
httpresponse.Errorf("unable to parse interactionConstraint from data. %s", err.Error()),
)
}

log.Infof("setting up proxy from %s to %s", proxyConfig.ServerAddress, proxyConfig.Target)
log.Infof("setting up proxy from %s to %s", proxyConfig.ServerAddress, proxyConfig.Target)

err = ConfigureProxy(proxyConfig)
if err != nil {
httpresponse.Errorf(w, http.StatusInternalServerError, "unable to create proxy from configuration. %s", err.Error())
return
}
err = ConfigureProxy(proxyConfig)
if err != nil {
return c.JSON(
http.StatusInternalServerError,
httpresponse.Errorf("unable to create proxy from configuration. %s", err.Error()),
)
}

return c.NoContent(http.StatusNoContent)
}
25 changes: 15 additions & 10 deletions internal/app/configuration/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import (
"strings"
"sync"

"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
)

var servers sync.Map

func GetServer(url *url.URL) (*http.ServeMux, error) {
rootServer, rootHandler, loaded := loadOrStoreHandler(url.Host, &http.Server{Addr: fmt.Sprintf(url.Host), Handler: http.NewServeMux()})
func GetServer(url *url.URL) (*echo.Echo, error) {
rootServer, loaded := loadOrStoreHandler(url.Host, echo.New())
if !loaded {
go func() {
if err := rootServer.ListenAndServe(); err != nil {
rootServer.HideBanner = true
if err := rootServer.Start(url.Host); err != nil {
if err != http.ErrServerClosed {
log.Error(err)
}
Expand All @@ -28,30 +30,33 @@ func GetServer(url *url.URL) (*http.ServeMux, error) {
if loaded {
return nil, fmt.Errorf("proxy already running at %s", url.String())
}
return rootHandler, nil
return rootServer, nil
}

addr := fmt.Sprintf("%s/%s", url.Host, strings.TrimLeft(url.Path, "/"))
_, proxyHandler, loaded := loadOrStoreHandler(addr, &http.Server{Handler: http.NewServeMux()})
proxyServer, loaded := loadOrStoreHandler(addr, echo.New())
if loaded {
return nil, fmt.Errorf("proxy already running at %s", addr)
}
proxyServer.HideBanner = true

rootHandler.Handle(url.Path+"/", http.StripPrefix(url.Path, proxyHandler))
rootServer.Any(url.Path+"/", echo.WrapHandler(http.StripPrefix(url.Path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
proxyServer.ServeHTTP(w, r)
}))))

return proxyHandler, nil
return proxyServer, nil
}

func loadOrStoreHandler(addr string, defaultServer *http.Server) (*http.Server, *http.ServeMux, bool) {
func loadOrStoreHandler(addr string, defaultServer *echo.Echo) (*echo.Echo, bool) {
server, loaded := servers.LoadOrStore(addr, defaultServer)
return server.(*http.Server), server.(*http.Server).Handler.(*http.ServeMux), loaded
return server.(*echo.Echo), loaded
}

func CloseAllServers() {
servers.Range(func(key, _ interface{}) bool {
server, loaded := servers.LoadAndDelete(key)
if loaded {
if err := server.(*http.Server).Close(); err != nil {
if err := server.(*echo.Echo).Close(); err != nil {
log.Error(err)
}
}
Expand Down
22 changes: 4 additions & 18 deletions internal/app/httpresponse/http.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
package httpresponse

import (
"encoding/json"
"fmt"
"net/http"

log "github.com/sirupsen/logrus"
)

func Error(w http.ResponseWriter, code int, error string) {
func Error(error string) *APIError {
log.Error(error)
e := &APIError{
ErrorMessage: error,
}

w.WriteHeader(code)
w.Header().Add("Content-Type", "application/json")

payload, err := json.Marshal(e)
if err != nil {
log.WithError(err).Error("could not marshal error into json")
}

_, err = fmt.Fprintln(w, payload)
if err != nil {
log.WithError(err).Error("could not write httpresponse error")
}
return e
}

func Errorf(w http.ResponseWriter, code int, error string, a ...interface{}) {
Error(w, code, fmt.Sprintf(error, a...))
func Errorf(error string, a ...interface{}) *APIError {
return Error(fmt.Sprintf(error, a...))
}
12 changes: 0 additions & 12 deletions internal/app/pactproxy/constraint.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package pactproxy

import (
"encoding/json"
"strings"

"github.com/pkg/errors"
)

type interactionConstraint struct {
Expand All @@ -15,15 +12,6 @@ type interactionConstraint struct {
Source string `json:"source"`
}

func LoadConstraint(data []byte) (interactionConstraint, error) {
constraint := interactionConstraint{}
err := json.Unmarshal(data, &constraint)
if err != nil {
return constraint, errors.Wrap(err, "unable to parse interactionConstraint from data")
}
return constraint, nil
}

func (i interactionConstraint) Key() string {
return strings.Join([]string{i.Interaction, i.Path}, "_")
}
12 changes: 0 additions & 12 deletions internal/app/pactproxy/modifier.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package pactproxy

import (
"encoding/json"
"fmt"
"strconv"
"strings"
"sync"
"sync/atomic"

"github.com/pkg/errors"
"github.com/tidwall/sjson"
)

Expand All @@ -24,16 +22,6 @@ type interactionModifiers struct {
modifiers sync.Map
}

func loadModifier(data []byte) (*interactionModifier, error) {
modifier := &interactionModifier{}
err := json.Unmarshal(data, &modifier)
if err != nil {
return modifier, errors.Wrap(err, "unable to parse interactionModifier from data")
}

return modifier, nil
}

func (im *interactionModifier) Key() string {
return strings.Join([]string{im.Interaction, im.Path}, "_")
}
Expand Down
Loading