Skip to content

Commit

Permalink
Expose vars pkg and some interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartin82 committed Aug 22, 2019
1 parent 1a17da4 commit b98c1fa
Show file tree
Hide file tree
Showing 29 changed files with 39 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ data/*
coverage.txt
.github
dist
.vscode
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ You can extract information from the request body too, using a dot notation path
- request.body."*key*" (support for `application/json`, `application/xml` and `application/x-www-form-urlencoded` requests)
- request.body."*deep*"."*key*" (support for `application/json`, `application/xml` requests)

Quick overview of the path syntax available to extract values form the request: [https://github.com/tidwall/gjson#path-syntax] (https://github.com/tidwall/gjson#path-syntax)
Quick overview of the path syntax available to extract values form the request: [https://github.com/tidwall/gjson#path-syntax](https://github.com/tidwall/gjson#path-syntax)

**External streams:** Perfect for embedding big payloads or getting data from another service.

Expand Down
15 changes: 8 additions & 7 deletions cmd/mmock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
"path/filepath"
"strings"

"github.com/jmartin82/mmock/internal/config"
"github.com/jmartin82/mmock/internal/config/parser"
"github.com/jmartin82/mmock/internal/console"
"github.com/jmartin82/mmock/internal/fs"
"github.com/jmartin82/mmock/internal/fs/parser"
"github.com/jmartin82/mmock/internal/server"
"github.com/jmartin82/mmock/internal/statistics"
"github.com/jmartin82/mmock/internal/vars"
"github.com/jmartin82/mmock/internal/vars/fake"
"github.com/jmartin82/mmock/pkg/config"
"github.com/jmartin82/mmock/pkg/match"
"github.com/jmartin82/mmock/pkg/match/payload"
"github.com/jmartin82/mmock/pkg/mock"
"github.com/jmartin82/mmock/pkg/vars"
"github.com/jmartin82/mmock/pkg/vars/fake"
)

//VERSION of the application
Expand Down Expand Up @@ -95,16 +96,16 @@ func getMapping(path string) config.Mapping {
log.Fatalln(ErrNotFoundPath.Error())
}

fsMapper := config.NewFileSystemMapper()
fsMapper := fs.NewFileSystemMapper()
fsMapper.AddParser(parser.JSONReader{})
fsMapper.AddParser(parser.YAMLReader{})

fsUpdate := make(chan struct{})

watcher := config.NewFileWatcher(path, fsUpdate)
watcher := fs.NewFileWatcher(path, fsUpdate)
watcher.Bind()

return config.NewConfigMapping(path, fsMapper, fsUpdate)
return fs.NewConfigMapping(path, fsMapper, fsUpdate)
}

func getRouter(mapping config.Mapping, checker match.Matcher) *server.Router {
Expand Down
7 changes: 4 additions & 3 deletions internal/console/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package console
import (
"errors"
"fmt"
"github.com/jmartin82/mmock/internal/config"
"log"
"net/http"
"regexp"
Expand All @@ -12,9 +11,11 @@ import (
"strings"

assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/jmartin82/mmock/pkg/mock"
"github.com/jmartin82/mmock/pkg/config"
"github.com/jmartin82/mmock/pkg/match"
"github.com/jmartin82/mmock/internal/statistics"
"github.com/jmartin82/mmock/pkg/mock"

"github.com/jmartin82/mmock/internal/statistics"
"github.com/labstack/echo"
"golang.org/x/net/websocket"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package fs

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package fs

import (
"errors"
Expand Down
9 changes: 1 addition & 8 deletions internal/config/mapping.go → internal/fs/mapping.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package fs

import (
"errors"
Expand All @@ -15,13 +15,6 @@ import (
var ErrFilePathIsNotUnderConfigPath = errors.New("File path is not under config path")
var ErrMockDoesntExist = errors.New("Definition doesn't exist")

type Mapping interface {
Set(URI string, mock mock.Definition) error
Delete(URI string) error
Get(URI string) (mock.Definition, bool)
List() []mock.Definition
}

//PrioritySort mock array sorted by priority
type PrioritySort []mock.Definition

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package fs

import (
"github.com/jmartin82/mmock/pkg/mock"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/config/watcher.go → internal/fs/watcher.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package fs

import (
"log"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package fs

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion internal/server/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"

"github.com/jmartin82/mmock/internal/statistics"
"github.com/jmartin82/mmock/internal/vars"
"github.com/jmartin82/mmock/pkg/vars"
"github.com/jmartin82/mmock/pkg/mock"
)

Expand Down
7 changes: 5 additions & 2 deletions internal/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package server
import (
"bytes"
"encoding/gob"
"github.com/jmartin82/mmock/internal/config"
"github.com/jmartin82/mmock/pkg/mock"

"github.com/jmartin82/mmock/pkg/config"

"log"

"github.com/jmartin82/mmock/pkg/mock"

"github.com/jmartin82/mmock/pkg/match"
)

Expand Down
10 changes: 10 additions & 0 deletions pkg/config/mapping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package config

import "github.com/jmartin82/mmock/pkg/mock"

type Mapping interface {
Set(URI string, mock mock.Definition) error
Delete(URI string) error
Get(URI string) (mock.Definition, bool)
List() []mock.Definition
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/vars/fake.go → pkg/vars/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package vars

import (
"errors"
"github.com/jmartin82/mmock/internal/vars/fake"
"github.com/jmartin82/mmock/pkg/vars/fake"
"log"
"reflect"
"regexp"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/vars/filler.go → pkg/vars/filler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package vars

import (
"github.com/jmartin82/mmock/internal/vars/fake"
"github.com/jmartin82/mmock/pkg/vars/fake"
"github.com/jmartin82/mmock/pkg/mock"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b98c1fa

Please sign in to comment.