An Upload/Version Schema API implementation using Go lang.
Follow these steps to clone and set up the project:
-
Clone the GitHub repository using the following command:
gh repo clone sumanth-vnm/levo_ai_schema_versioning_system
-
Open a terminal in the installed repos' root directory and initialize go module using
go mod init example.com/levo_app
-
Install dependencies using
go mod tidy
Follow the below steps, to set up the postgres database connection to the go project:
-
Use any existing database or create a new database in postgres. Let's say we are using a database named "levo_app_db"
-
create a new sequence in the database using the following command:
CREATE SEQUENCE levo_sequence START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
-
create a new table in the database using the following command (This table uses the above sequence to generate the primary key):
CREATE TABLE schemas( id BIGINT PRIMARY KEY DEFAULT nextval('levo_sequence'), filename TEXT, version BIGINT, created_on TIMESTAMPTZ );
-
Inside the cloned project, in the file "db/database.go", update the database connection parameters which looks like below:
username := "postgres" password := "sam123" dbName := "levo_app_db"
-
to run this project, use the following command:
go run main.go
-
This will start the server at port 8080. if port needs to be changed, update the port number in the file "main.go" which looks like below:
http.ListenAndServe(":8080", router)
Following are the API endpoints implemented in this project:
localhost:8080/upload/schema - (POST) - to upload a new schema file[json/yaml]
Note: Use the field key "file" inside body to upload any schema file
Output: If successful, returns the "version" and success "message"
localhost:8080/getLatestSchema/{{filename}} - (GET) - to get the latest schema file
Output: If successful, returns the latest schema file with field "filename" and "version" number
localhost:8080/getSchemaByVersion/{{filename}}/{version} - (GET) - to get the schema file of a particular file name and version
Output: If successful, returns the schema file of requested version number
localhost:8080/getAllVersions/{{filename}} - (GET) - to get all the schema files
Output: If successful, returns "available_versions" array with all the versions of the requested file name
-
Once a schema is uploaded, The uploaded files will be stored under "schema_uploads" folder in the root directory of the project.
-
For every new schema file uploaded, a new directory will be created with the name of the file under the "schema_uploads" folder.
-
Inside the directory of the uploaded file, naming of the different versions will be 1.json, 2.json, 3.json, etc. or with yaml type extensions.
a postman collection json file is added in the repository at the root folder named "Levo.ai.postman_collection.json". This file can be imported into postman to test the API endpoints.