Code Monkey home page Code Monkey logo

nearby's Introduction

nearby

Nearby API, to search nearby phone area codes

Goal of this project

Trying to implement an API that will return data from a database without using any external go modules (or the least amount of modules).

The idea is to work on a project from a scratch to get familiar with the golang ecosystem, development cycle and tooling

References and coding standards

Tasks:

  • Connect to a database
  • Add unit tests
  • Implement repository pattern
  • Define/implement endpoints
  • Add auto generated swagger doc?

Documentation

Start project

Install all needed components with go get:

go get ./...

Commands

Currently, this project has two different commands, one to start the API and another one to seed the API.

API

To start the API run:

go run cmd/nearby/main.go

This should start the API in port 8080, if you want to change the port use set the environment var PORT to you desired port

Environment variables
  • PORT: Changes the port where the API will run (default: 8080)
  • SQLITE_DNS: DNS to connect to a database (default: data/db.sqlite)

Seed

To run the database seeder:

go run cmd/seed/sqlite.go

This will insert rows in the only SQL table used by the API nearby_area_codes. Currently, it searches for a .sql file called ./data/data.sql. The file should contain the INSERT statements to seed your database. For example:

INSERT INTO `nearby_area_codes` VALUES (1,360,564)

For more information on the database schema check data/schema.sql

Test

Run project tests with:

go test ./...

Generate swagger doc

This project uses https://github.com/swaggo/swag to generate swagger file

swag init -g cmd/nearby/main.go --ot yaml -o api/

Docker

You can build and run this project as a docker container.

Make sure you already have your ./data/data.sql file in place before building the image

First you need to build the docker image:

docker build -t nearby-api .

And then run it in the exposed port:

docker run -p 8080:8080 nearby-api:latest

This will run the project in localhost:8080

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.