Git Product home page Git Product logo

gin-demo's Introduction

gin-demo

一、项目内容

基于gin框架的demo项目,本项目基于B站视频Go语言 Gin+Vue 前后端分离实战 - OceanLearn https://www.bilibili.com/video/BV1CE411H7bQ?t=7

master分支为后端go代码,vue分支为前端vue代码

二、怎样运行该项目

2.1 运行后端程序

先确保你电脑上正确安装了 golang 环境

从master分支拉取后端golang代码

# 拉取代码
git clone -b main https://github.com/kotlindev/gin-demo.git backend
# 进入项目目录
cd  backend
# 安装项目依赖
go get

打开 config/application.yaml 文件,修改数据库链接配置,修改项目运行端口,确保端口不被占用,参考如下

server:
  port: 8081
datasource:
  driverName: mysql
  host: 127.0.0.1
  port: 3306
  database: api
  username: pan
  password: www.phy.xyz
  charset: utf8
  loc: Asia/Shanghai

启动项目

go run routes.go main.go

如果看到命令行终端输出以下路由信息,代表项目运行正常。如果不正常,检查一下数据库地址还有账号密码是否正确,同时确保运行的端口没有被占用

[GIN-debug] POST   /api/auth/register        --> jkdev.cn/api/controller.Register (5 handlers)
[GIN-debug] POST   /api/auth/login           --> jkdev.cn/api/controller.Login (5 handlers)
[GIN-debug] GET    /api/auth/info            --> jkdev.cn/api/controller.Info (6 handlers)
[GIN-debug] POST   /categories               --> jkdev.cn/api/controller.ICategoryController.Create-fm (5 handlers)
[GIN-debug] PUT    /categories/:id           --> jkdev.cn/api/controller.ICategoryController.Update-fm (5 handlers)
[GIN-debug] GET    /categories/:id           --> jkdev.cn/api/controller.ICategoryController.Show-fm (5 handlers)
[GIN-debug] DELETE /categories/:id           --> jkdev.cn/api/controller.ICategoryController.Delete-fm (5 handlers)
[GIN-debug] POST   /posts                    --> jkdev.cn/api/controller.IPostController.Create-fm (6 handlers)
[GIN-debug] PUT    /posts/:id                --> jkdev.cn/api/controller.IPostController.Update-fm (6 handlers)
[GIN-debug] GET    /posts/:id                --> jkdev.cn/api/controller.IPostController.Show-fm (6 handlers)
[GIN-debug] DELETE /posts/:id                --> jkdev.cn/api/controller.IPostController.Delete-fm (6 handlers)
[GIN-debug] POST   /posts/page/list          --> jkdev.cn/api/controller.IPostController.PageList-fm (6 handlers)
[GIN-debug] Listening and serving HTTP on :8081

2.2 运行前端程序

先确保你电脑上正确安装了 npm 环境,并安装了 vue、yarn

从vue分支拉取前端vue代码

# 拉取代码
git clone -b vue https://github.com/kotlindev/gin-demo.git vue
# 进入项目目录
cd  vue
# 安装项目依赖
yarn install

根据1中的 后端代码的运行端口,修改 .env.development.local.env.development 两个配置文件,修改配置如下为

VUE_APP_BASE_URL = http://localhost:8081/api/

在运行项目

yarn serve

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.