generated from rog-golang-buddies/golang-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from rog-golang-buddies/base_infrastrastructure
Base infrastrastructure
- Loading branch information
Showing
24 changed files
with
634 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package fileresource | ||
|
||
// FileResource representation of file resource | ||
type FileResource struct { | ||
//File name if exists, else empty | ||
Name string | ||
|
||
//Original link to file | ||
Link string | ||
|
||
//File content | ||
Content []byte | ||
|
||
//Type of the API specification file (json/yaml ...) | ||
Type AsdFileType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fileresource | ||
|
||
type AsdFileType int | ||
|
||
const ( | ||
Undefined AsdFileType = iota | ||
YamlOpenApi | ||
JsonOpenAPI | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package load | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/fileresource" | ||
) | ||
|
||
//ContentLoader loads content by url | ||
//go:generate mockgen -source=contentLoader.go -destination=./mocks/contentLoader.go -package=load | ||
type ContentLoader interface { | ||
Load(ctx context.Context, url string) (*fileresource.FileResource, error) | ||
} | ||
|
||
type ContentLoaderImpl struct { | ||
} | ||
|
||
// Gets context and an url of a OpenApi file (Swagger file) string as parameter and returns a FileResource containing the link, optionally name and main content of the file. | ||
func (cl *ContentLoaderImpl) Load(ctx context.Context, url string) (*fileresource.FileResource, error) { | ||
//load content by url | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
func NewContentLoader() ContentLoader { | ||
return &ContentLoaderImpl{} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package parse | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/apiSpecDoc" | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/fileresource" | ||
) | ||
|
||
// Converter converts file data to API specification document using specific file type | ||
// | ||
//go:generate mockgen -source=converter.go -destination=./mocks/converter.go -package=parse | ||
type Converter interface { | ||
Convert(file *fileresource.FileResource) (*apiSpecDoc.ApiSpecDoc, error) | ||
} | ||
|
||
type ConverterImpl struct { | ||
//For instance, we may have a map to hold parsers for different types. And populate it in NewConverter | ||
parsers map[fileresource.AsdFileType]Parser | ||
} | ||
|
||
// Convert gets bytes slice with json/yaml content and a filetype matching the type of the content and returns parsed ApiSpecDoc. | ||
func (c *ConverterImpl) Convert(file *fileresource.FileResource) (*apiSpecDoc.ApiSpecDoc, error) { | ||
//Just example | ||
parser, ok := c.parsers[file.Type] | ||
if !ok { | ||
return nil, errors.New("file type not supported") | ||
} | ||
apiSpec, err := parser.parse(file.Content) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return apiSpec, nil | ||
} | ||
|
||
func NewConverter(parsers []Parser) Converter { | ||
parsersMap := make(map[fileresource.AsdFileType]Parser) | ||
for _, parser := range parsers { | ||
parsersMap[parser.getType()] = parser | ||
} | ||
return &ConverterImpl{ | ||
parsers: parsersMap, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package parse | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestNewConverter(t *testing.T) { | ||
parsers := []Parser{NewYamlOpenApiParser(), NewJsonOpenApiParser()} | ||
converter := NewConverter(parsers) | ||
assert.NotNil(t, converter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package parse | ||
|
||
import ( | ||
"errors" | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/apiSpecDoc" | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/fileresource" | ||
) | ||
|
||
//JsonOpenApiParser implementation for parsing json open API files | ||
type JsonOpenApiParser struct { | ||
} | ||
|
||
func (joap *JsonOpenApiParser) parse(content []byte) (*apiSpecDoc.ApiSpecDoc, error) { | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
func (joap *JsonOpenApiParser) getType() fileresource.AsdFileType { | ||
return fileresource.JsonOpenAPI | ||
} | ||
|
||
func NewJsonOpenApiParser() Parser { | ||
return &JsonOpenApiParser{} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package parse | ||
|
||
import ( | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/apiSpecDoc" | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/fileresource" | ||
) | ||
|
||
//Parser is common interface with functionality | ||
//to parse content of the specific API specification document | ||
//and to construct ApiSpecDoc object from it | ||
type Parser interface { | ||
// parses the bytes slice to a ApiSecDoc | ||
parse(content []byte) (*apiSpecDoc.ApiSpecDoc, error) | ||
|
||
// returns the type (json or yaml) of the parser | ||
getType() fileresource.AsdFileType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package parse | ||
|
||
import ( | ||
"errors" | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/apiSpecDoc" | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/fileresource" | ||
) | ||
|
||
//YamlOpenApiParser implementation for parsing yml open API files | ||
type YamlOpenApiParser struct { | ||
} | ||
|
||
func (yoap *YamlOpenApiParser) parse(content []byte) (*apiSpecDoc.ApiSpecDoc, error) { | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
func (yoap *YamlOpenApiParser) getType() fileresource.AsdFileType { | ||
return fileresource.JsonOpenAPI | ||
} | ||
|
||
func NewYamlOpenApiParser() Parser { | ||
return &YamlOpenApiParser{} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.