Coder Social home page Coder Social logo

gocrudbook's Introduction

GoCrudBook

drawing

CRUD API example is written in Go using net/http package and MySQL database.

Requirements

Project Structure

GoCrudBook  
├── LICENSE.md   
├── cmd 
│   └── web
│       ├── config
│       │   └── config.go
│       ├── database
│       │   └── connection.go
│       ├── handler
│       │   └── handler.go
│       ├── main.go
│       └── router
│           └── router.go
├── go.mod
├── go.sum
├── gopher-lib.jpeg
├── pkg
│   └── models
│       ├── book.go
│       └── mysql
│           ├── book.sql
│           └── mysql.go
└── to-do.md

Instructions

  • Clone the repository and move to the project directory:
      git clone https://github.com/3n0ugh/GoCrudBook.git
      cd GoCrudBook
  • To load the database
    • To create a database into MySQL:
        CREATE DATABASE library;
    • Then, create a table and insert sample values into the database:
        mysql -u root library < pkg/models/book.sql
  • Tidy the modules
      go mod tidy
  • Run the main.go
      go run ./cmd/web/main.go -port 5000 -dsn "root@/library"

Usage Examples

  • Get All Book
  curl -X GET localhost:5000/book
  • Get Book (by id)
  curl -X GET "localhost:5000/book/id?id=1933988673"
  • Get Book (by name) (enough to contain the word)
  curl -X GET "localhost:5000/book/name?name=android"
  • Add Book
  curl -X POST localhost:5000/book/create -d
    '{ "isbn" : 1932394161,
        "book_name" : "Time To Go Forward",
        "author": "3n0ugh",
        "page_count" : 14,
        "book_count": 1,
        "borrow_times": 3,
        "barrow_date": null,
        "last_recieved_dat": null
       }'
  • Delete Book (by id)
  curl -X DELETE "localhost:5000/book/delete?id=1932394161"
  • Update Book
  curl -X PUT localhost:5000/book/update -d 
     '{ "isbn" : 1932394161,
        "book_name" : "Time To Go Forward",
        "author": "3n0ugh",
      	"page_count" : 14,
        "book_count": 1,
        "borrow_times": 3,
        "barrow_date": null,
        "last_recieved_dat": null
       }'

gocrudbook's People

Contributors

3n0ugh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gitart

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.