App metadata is a REST-API to store a metadata in yaml format
- It requires go version >= 1.11 to enable go modules
- Clone it from https://github.com/elumbantoruan/app-metadata.git (https) or git@github.com:elumbantoruan/app-metadata.git (ssh)
- To build, run go build ./...
- To run unit test, run go test ./...
- To run the app, execute go run main.go. This will enable the endpoint at localhost:5000/app-metadata
- Example of POST operation returns 201, and the created payload
curl -d '
> title: Valid App 1
> version: 1.0.1
> maintainers:
> - name: First Maintainer App1
> email: firstmaintainer@hotmail.com
> - name: Second Maintainer App1
> email: secondmaitainer@gmail.com
> company: pellucid Computing
> website: http://pellucidcomputing.com
> source: https://github.com/company/app-metadata
> license: Apache-2.0
> description: |-
> ### Interesting title
> Some application content' -i http://localhost:5000/app-metadata
- Example of POST operation returns 400 because of invalid payload
curl -d '
> title: Valid App 1
> maintainers:
> - name: First Maintainer App1
> email: firstmaintainer@hotmail.com
> - name: Second Maintainer App1
> email: secondmaitainer@gmail.com
> company: pellucid Computing
> website: http://pellucidcomputing.com
> source: https://github.com/company/app-metadata
> license: Apache-2.0
> description: |-
> ### Interesting title
> Some application content' -i http://localhost:5000/app-metadata
Go modules (go.mod) will simply download all dependencies after running the build command
- Gorilla mux It's URL router and dispatcher
- UUID It's a UUID to generate a unique id
- Testify Tools for unit test such as assert, suite, and mock]
- yaml YAML support for the Go language
MetadataHandler contains a set of methods to perform POST, PUT, GET, and DELETE for REST API operations.
Here are the list of http methods along with response code
POST /app-metadata
201 - resource created
400 - invalid yaml format, missing required field
500 - error from data storage
PUT /app-metadata/{appID}
200 - resource updated
400 - invalid yaml format, missing required field
409 - conflict when id is not found during update
500 - error from data storage
GET /app-metadata/{appID}
200 - resource is found and returned
400 - missing appID parameter
404 - resources not found (appID is not found in storage)
500 - error from data storage
GET /app-metadata
200 - resource is found and returned
404 - resource not found
500 - error from data storage
DELETE /app-metadata/{appID}
204 - resource deleted (no content)
400 - missing appID parameter
409 - conflict when id is not found during delete
500 - error from data storage
It has a dependency on repository interface to perform a create, get, update, and delete repository actions.
It also contains a unit test for all REST API operations
ApplicationMetadata is a payload used in the application which is marshalled into yaml format
Repository contains a MetadataRepository interface and InMemoryMetadataRepository type. The intent of the interface is to allow flexibility for swapping different repository mechanisms. It also enables a mock up repository to be used in unit test
type MetadataRepository interface {
Create(appID string, data *metadata.ApplicationMetadata) error
Update(appID string, data *metadata.ApplicationMetadata) error
Get(appID string) (*metadata.ApplicationMetadata, error)
GetAll() ([]metadata.ApplicationMetadata, error)
Delete(appID string) error
}
InMemoryMetadataRepository is a concrete implementation of MetadataRepository interface