Skip to content

norberteder/golang_webapidemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang_webapidemo

Web API demo with MySQL support

Starting the sample application

Clone this repository

git clone [email protected]:norberteder/golang_webapidemo.git
cd golang_webapidemo

Start the sample application using Docker Compose

docker-compose up -d

Endpoints

Create a new contact

http post http://localhost:8081/api/1/contacts firstName=Norbert lastName=Eder [email protected]

Get all contacts

http get http://localhost:8081/api/1/contacts

Expected result:

[
    {
        "email": "[email protected]",
        "firstName": "Norbert",
        "id": 1,
        "lastName": "Eder"
    }
]

(Sample API calls use HTTPie)

Troubleshooting

If the http calls don't work it might caused by the crashed app container. This can happen if the database is starting to slow and is not available when the app container is trying to access it on startup (the app should use some retry for database connections).

To validate this, just run docker logs golangwebapidemo_app_1.

The result might be:

2018/04/13 20:15:28 Initializing database ...
2018/04/13 20:15:28 dial tcp 172.31.0.2:3306: connect: connection refused
panic: dial tcp 172.31.0.2:3306: connect: connection refused

If this is the result, just wait a few seconds and re-run docker-compose up -d

About

Go web api demo with MySQL usage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages