GithubHelp home page GithubHelp logo

emxqm-11 / go-bank-backend Goto Github PK

View Code? Open in Web Editor NEW

This project forked from duomly/go-bank-backend

0.0 0.0 0.0 29 KB

This is code for the Duomly course - Learn Golang by building a bank app

Go 100.00%

go-bank-backend's Introduction

Golang banking app

This is app for the Duomly Golang Course - Learn Golang by building banking App

Run

  • Setup a PostgreSQL db * Troubleshoot section for more details
  • You need to setup your connection string in the two files, vulnerable-db.go, and migrations.go
  • Start migration by commenting migration in main.go and commenting API
func main() {
	// Init database
	database.InitDatabase()
	// Do migration
	migrations.Migrate()
	// api.StartApi()
}
  • Run (this migrate to your db):
go run main.go
  • Comment out migration and uncomment api (to start server)
func main() {
	// Init database
	database.InitDatabase()
	// Do migration
	// migrations.Migrate()
	api.StartApi()
}
  • Run:
go run main.go

This should start your server on localhost:8888

API Examples

To register a new user:

Use this json as the body of your payload in a POST request to localhost:8888/register

{
	"username": "xxxxxx",
	"email": "[email protected]",
	"password": "some_password"
}

Example response from /register:

{
  "data": {
    "ID": 5,
    "Username": "xxxxxx",
    "Email": "[email protected]",
    "Accounts": [
      {
        "ID": 5,
        "Name": "xxxxxx's account",
        "Balance": 0
      }
    ]
  },
  "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcnkiOjE2MTAxODQ1ODgsInVzZXJfaWQiOjV9.E8FXVYmz_N_IL0WnC9COO2XyrHc7HFPjmQUaeg3MKjk",
  "message": "all is fine"
}

To send a transaction: Use this json as the body of your payload in a POST request to localhost:8888/transaction

Make sure that you add your "jwt" token you obtain from /login or /register response and add that as your request's Authorization Bearer token.

{
	"UserId" : 1,
	"From": 1,
	"To": 3,
	"Amount" : 1000
}

Troubleshoot (Mac)

When you're setting up your postgres db for the first time on a mac you can run:

createuser -s postgres - fixes role "postgres" does not exist
createdb bankapp - fixes database "bankapp" does not exist

go-bank-backend's People

Contributors

emxqm-11 avatar radoslawfabisiak avatar

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.