All Projects → ybkuroki → go-webapp-sample

ybkuroki / go-webapp-sample

Licence: MIT license
golang, echo, gorm

Programming Languages

go
31211 projects - #10 most used programming language
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to go-webapp-sample

Goweibo
Go Weibo App
Stars: ✭ 243 (+25.26%)
Mutual labels:  echo, gorm
Echo Web
Go web framework Echo example. 在线演示☞迁移ing❌
Stars: ✭ 409 (+110.82%)
Mutual labels:  echo, gorm
go-echo-server-sandbox
A scaffold of golang web server using labstack/echo
Stars: ✭ 12 (-93.81%)
Mutual labels:  echo, gorm
Logrus
Hooks for logrus logging
Stars: ✭ 110 (-43.3%)
Mutual labels:  echo, gorm
echo-gorm-realworld-app
realworld application built with Golang + Echo + Gorm
Stars: ✭ 18 (-90.72%)
Mutual labels:  echo, gorm
Phalgo
phalgo 已经更换为 https://github.com/sunmi-OS/gocore phalgo不在维护
Stars: ✭ 110 (-43.3%)
Mutual labels:  echo, gorm
golang-example-app
Example application
Stars: ✭ 138 (-28.87%)
Mutual labels:  gorm
gorm-paginator
gorm pagination extension
Stars: ✭ 154 (-20.62%)
Mutual labels:  gorm
server-benchmarks
🚀 Cross-platform transparent benchmarks for HTTP/2 Web Servers at 2020-2023
Stars: ✭ 78 (-59.79%)
Mutual labels:  echo
Goview
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.
Stars: ✭ 213 (+9.79%)
Mutual labels:  echo
ginadmin
基于Gin开发的后台管理系统,集成了、数据库操作、日志管理、权限分配管理、多模板页面、自动分页器、数据库迁移和填充、Docker集成部署等功能、静态资源打包
Stars: ✭ 149 (-23.2%)
Mutual labels:  gorm
go api boilerplate
🐶Go (Golang)🚀REST / GraphQL API + Postgres boilerplate
Stars: ✭ 127 (-34.54%)
Mutual labels:  gorm
go-orm-code-helper
🔥🔥🔥go-orm-code-helper is a goland plugin, it aims to make gorm code getting more simple
Stars: ✭ 22 (-88.66%)
Mutual labels:  gorm
BEW-2.5-Strongly-Typed-Languages
💪 Learn and implement the design patterns and best practices that make Go a top choice at high-velocity startups like Lyft, Heroku, Docker, Medium, and more!
Stars: ✭ 14 (-92.78%)
Mutual labels:  gorm
simple-wallet
This is a simple wallet REST api that is capable of acount deposits and withdrawals, checking for account balance and providing a ministatement. It follows domain driven design practices. The project uses the DDD architecture approach.
Stars: ✭ 32 (-83.51%)
Mutual labels:  gorm
Echo
Echo Documentation.
Stars: ✭ 23 (-88.14%)
Mutual labels:  echo
go-starter
Go 服务框架脚手架. 整合 echo、swag、viper、nsq、logrus、fx、xorm、cobra 等第三方库
Stars: ✭ 145 (-25.26%)
Mutual labels:  echo
simple-mpesa
A simple example of how MPESA works. Works with all 3 types of customers i.e. Agents, Merchants and Subscribers. Allows you to configure a tariff and apply it to transactions. The project follows DDD principles.
Stars: ✭ 31 (-84.02%)
Mutual labels:  gorm
go-graphql-api-boilerplate
A Boilerplate of GraphQL API built in Go + graphql-go + gorm
Stars: ✭ 75 (-61.34%)
Mutual labels:  gorm
gorm-mongodb
GORM for MongoDB
Stars: ✭ 58 (-70.1%)
Mutual labels:  gorm

go-webapp-sample

license report workflow release

Preface

This repository is the sample of web application using golang. This sample uses Echo as web application framework, Gorm as OR mapper and Zap logger as logger. This sample application provides only several functions as Web APIs. Please refer to the 'Service' section about the detail of those functions.

Also, this application contains the static contents such as html file, css file and javascript file which built vuejs-webapp-sample project to easily check the behavior of those functions. So, you can check this application without starting a web server for front end. Please refer to the 'Starting Server' section about checking the behavior of this application.

If you would like to develop a web application using golang, please feel free to use this sample.

Install

Perform the following steps:

  1. Download and install MinGW(gcc).
  2. Download and install Visual Studio Code(VS Code).
  3. Download and install Golang.
  4. Get the source code of this repository by the following command.
    go install github.com/ybkuroki/go-webapp-sample@latest

Starting Server

There are 2 methods for starting server.

Without Web Server

  1. Starting this web application by the following command.
    go run main.go
  2. When startup is complete, the console shows the following message:
    http server started on [::]:8080
    
  3. Access http://localhost:8080 in your browser.
  4. Login with the following username and password.
    • username : test
    • password : test

With Web Server

Starting Application Server

  1. Starting this web application by the following command.
    go run main.go
  2. When startup is complete, the console shows the following message:
    http server started on [::]:8080
    
  3. Access http://localhost:8080/api/health in your browser and confirm that this application has started.
    healthy
    

Starting Web Server

  1. Clone vuejs-webapp-sample project and install some tools.
  2. Start by the following command.
    npm run serve
  3. When startup is complete, the console shows the following message:
    DONE Compiled successfully in *****ms
    
    App running at:
    - Local:   http://localhost:3000/
    - Network: http://192.168.***.***:3000/
    
    Note that the development build is not optimized.
    To create a production build, run npm run build.
    
  4. Access http://localhost:3000 in your browser.
  5. Login with the following username and password.
    • username : test
    • password : test

Using Swagger

In this sample, Swagger is enabled only when executed this application on the development environment. Swagger isn't enabled on the another environments in default.

Accessing to Swagger

  1. Start this application according to the 'Starting Application Server' section.
  2. Access http://localhost:8080/swagger/index.html in your browser.

Updating the existing Swagger document

  1. Update some comments of some controllers.
  2. Download Swag library. (Only first time)
    go install github.com/swaggo/swag/cmd/swag@latest
  3. Update docs/docs.go.
    swag init

Build executable file

Build this source code by the following command.

go build main.go

Project Map

The follwing figure is the map of this sample project.

- go-webapp-sample
  + config                  … Define configurations of this system.
  + logger                  … Provide loggers.
  + middleware              … Define custom middleware.
  + migration               … Provide database migration service for development.
  + router                  … Define routing.
  + controller              … Define controllers.
  + model                   … Define models.
  + repository              … Provide a service of database access.
  + service                 … Provide a service of book management.
  + session                 … Provide session management.
  + test                    … for unit test
  - main.go                 … Entry Point.

Services

This sample provides 3 services: book management, account management, and master management. Regarding the detail of the API specification, please refer to the 'Using Swagger' section.

Book Management

There are the following services in the book management.

Service Name HTTP Method URL Parameter Summary
Get Service GET /api/books/[BOOK_ID] Book ID Get a book data.
List/Search Service GET /api/books?query=[KEYWORD]&page=[PAGE_NUMBER]&size=[PAGE_SIZE] Page, Keyword(Optional) Get a list of books.
Regist Service POST /api/books Book Regist a book data.
Edit Service PUT /api/books Book Edit a book data.
Delete Service DELETE /api/books Book Delete a book data.

Account Management

There are the following services in the Account management.

Service Name HTTP Method URL Parameter Summary
Login Service POST /api/auth/login Session ID, User Name, Password Session authentication with username and password.
Logout Service POST /api/auth/logout Session ID Logout a user.
Login Status Check Service GET /api/auth/loginStatus Session ID Check if the user is logged in.
Login Username Service GET /api/auth/loginAccount Session ID Get the login user's username.

Master Management

There are the following services in the Master management.

Service Name HTTP Method URL Parameter Summary
Category List Service GET /api/categories Nothing Get a list of categories.
Format List Service GET /api/formats Nothing Get a list of formats.

Tests

Create the unit tests only for the packages such as controller, service, model/dto and util. The test cases is included the regular cases and irregular cases. Please refer to the source code in each packages for more detail.

The command for testing is the following:

go test ./... -v

Libraries

This sample uses the following libraries.

Library Name Version
echo 4.9.0
gorm 1.23.10
go-playground/validator.v9 9.31.0
zap 1.23.0

Contribution

Please read CONTRIBUTING.md for proposing new functions, reporting bugs and submitting pull requests before contributing to this repository.

License

The License of this sample is MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].