• Stars
    star
    327
  • Rank 128,686 (Top 3 %)
  • Language
    Go
  • Created almost 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gohub,以论坛 API 为主题,设计的初衷是将其打造为高性能、功能齐全的 API 框架。基于 gin, cobra, viper, zap, gorm, redis, mysql, sqlite, email, jwt

gohub

本项目是 《G02 Go API 实战》 实战课程的源码,基于 MIT 协议开源。

项目名称 Gohub,以论坛 API 为主题,设计的初衷是将其打造为高性能、功能齐全的 API 框架。基于 gin, cobra, viper, zap, gorm, redis, mysql, sqlite, email, jwt.

程序结构说明,请见 程序结构

RESTful API 最佳实践

一套优秀的 API 设计,需要具备如下特性:

  1. 使用 HTTPS
  2. 使用域名
  3. 版本区分
  4. 使用 URL 来定位资源
  5. 使用 HTTP 动词来描述操作
  6. 支持资源过滤
  7. 使用 HTTP 状态码
  8. 数据响应的一致性
  9. 支持限流
  10. API 文档
  11. 自带分页链接
  12. 强制 User-Agent

详细讲解请见 RESTful API 最佳实践

所有路由

请求方法 API 地址 说明
POST /api/v1/auth/login/using-phone 短信 + 手机号登录
POST /api/v1/auth/login/using-password 手机号、用户名、邮箱 + 密码
POST /api/v1/auth/login/refresh-token 刷下 Token
POST /api/v1/auth/password-reset/using-email 邮件密码重置
POST /api/v1/auth/password-reset/using-phone 短信验证码密码重置
POST /api/v1/auth/signup/using-phone 使用手机号注册
POST /api/v1/auth/signup/using-email 使用邮箱注册
POST /api/v1/auth/signup/phone/exist 手机号是否已注册
POST /api/v1/auth/signup/email/exist email 是否已支持
POST /api/v1/auth/verify-codes/phone 发送短信验证码
POST /api/v1/auth/verify-codes/email 发送邮件验证码
POST /api/v1/auth/verify-codes/captcha 获取图片验证码
GET /api/v1/user 获取当前用户
GET /api/v1/users 用户列表
PUT /api/v1/users 修改个人资料
PUT /api/v1/users/email 修改邮箱
PUT /api/v1/users/phone 修改手机号
PUT /api/v1/users/password 修改密码
PUT /api/v1/users/avatar 上传头像
GET /api/v1/categories 分类列表
POST /api/v1/categories 创建分类
PUT /api/v1/categories/:id 更新分类
DELETE /api/v1/categories/:id 删除分类
GET /api/v1/topics 话题列表
POST /api/v1/topics 创建话题
PUT /api/v1/topics/:id 更新话题
DELETE /api/v1/topics/:id 删除话题
GET /api/v1/topics/:id 获取话题
GET /api/v1/links 友情链接列表

第三方依赖

使用到的开源库:

自定义的包

现在来看下我们自建的库:

  • app —— 应用对象
  • auth —— 用户授权
  • cache —— 缓存
  • captcha —— 图片验证码
  • config —— 配置信息
  • console —— 终端
  • database —— 数据库操作
  • file —— 文件处理
  • hash —— 哈希
  • helpers —— 辅助方法
  • jwt —— JWT 认证
  • limiter —— API 限流
  • logger —— 日志记录
  • mail —— 邮件发送
  • migrate —— 数据库迁移
  • paginator —— 分页器
  • redis —— Redis 数据库操作
  • response —— 响应处理
  • seed —— 数据填充
  • sms —— 发送短信
  • str —— 字符串处理
  • verifycode —— 数字验证码

代码行数

Gohub 项目总共有 4600 行代码(工具 gocloc):

$ gocloc .
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                             122           1200            865           4629
TOML                             1              7             21             28
-------------------------------------------------------------------------------
TOTAL                          123           1207            886           4657
-------------------------------------------------------------------------------

所有命令

$ go run main.go -h
Default will run "serve" command, you can use "-h" flag to see all subcommands

Usage:
   [command]

Available Commands:
  cache       Cache management
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  key         Generate App Key, will print the generated Key
  make        Generate file and code
  make        Generate file and code
  migrate     Run database migration
  play        Likes the Go Playground, but running at our application context
  seed        Insert fake data to the database
  serve       Start web server

Flags:
  -e, --env string   load .env file, example: --env=testing will use .env.testing file
  -h, --help         help for this command

Use " [command] --help" for more information about a command.

make 命令:

$ go run main.go make -h
Generate file and code

Usage:
   make [command]

Available Commands:
  apicontroller Create api controller,exmaple: make apicontroller v1/user
  cmd           Create a command, should be snake_case, exmaple: make cmd buckup_database
  factory       Create model's factory file, exmaple: make factory user
  migration     Create a migration file, example: make migration add_users_table
  model         Crate model file, example: make model user
  policy        Create policy file, example: make policy user
  request       Create request file, example make request user
  seeder        Create seeder file, example:  make seeder user

Flags:
  -h, --help   help for make

Global Flags:
  -e, --env string   load .env file, example: --env=testing will use .env.testing file

Use " make [command] --help" for more information about a command.

migrate 命令:

$ go run main.go migrate -h
Run database migration

Usage:
   migrate [command]

Available Commands:
  down        Reverse the up command
  fresh       Drop all tables and re-run all migrations
  refresh     Reset and re-run all migrations
  reset       Rollback all database migrations
  up          Run unmigrated migrations

Flags:
  -h, --help   help for migrate

Global Flags:
  -e, --env string   load .env file, example: --env=testing will use .env.testing file

Use " migrate [command] --help" for more information about a command.

More Repositories

1

laravel-shop

Laravel 电商实战教程的项目代码
PHP
2,443
star
2

phphub5

PHPHub Ver 5 is a Forum project Powered by Laravel 5.1, and it is also the project build up PHP & Laravel China community (此项目已弃用)
PHP
1,946
star
3

phphub

(Deprecated See - https://github.com/summerblue/phphub5 ) PHPHub is a Forum project written in Laravel 4.2, and it is also the project build up PHP & Laravel China community - http://phphub.org.
PHP
1,814
star
4

larabbs

A forum project base on Laravel
HTML
1,066
star
5

laravel-package-top-100

对 Packagist 上打了 Laravel 标签 的扩展包进行整理,截止到现在 2016 年 8 月 9号,有超过 7176 个扩展包,以下是下载量最大的 100 个。
PHP
993
star
6

laravel5-cheatsheet

A quick reference guide (cheat sheet) for Laravel 5.1 LTS, listing artisan, composer, routes and other useful bits of information.
PHP
786
star
7

laravel-ubuntu-init

A shell script for setting up Laravel Production environment on Ubuntu 14.04 & Ubuntu 16 & Ubuntu 18 system.
Shell
748
star
8

psr.phphub.org

PSR 中文翻译
CSS
390
star
9

news.laravel-china.org

Source Code of the https://news.laravel-china.org/ website, build on top of Laravel 5.1. Laravel 资讯网站源代码,使用 Laravel 5.1 构建
PHP
365
star
10

generator

Laravel 5.3+ Scaffold Generator, Support both bootstrap and Semantic UI
PHP
334
star
11

administrator

a fork from Frozennode/Administrator
CSS
290
star
12

phphub-ui

Product planing and UI Design for PHPHub App and Web site.
278
star
13

laravel-blog

Laravel-Blog is a blog application written in Laravel 4.2.
JavaScript
191
star
14

goblog

Goblog 是一个基于 Go 标准库构建的博客系统。此项目非常适合作为 Go 新手的第一个上手项目。
Go
186
star
15

laravel-tutorial

Laravel 中文新手书籍《Laravel 入门教程》的源代码
PHP
145
star
16

laravel-tutorial-sample

PHP
137
star
17

weibo

Laravel 中文新手课程《L01 Laravel 教程 - Web 开发实战入门》的源代码
PHP
105
star
18

github-toc

Chrome Extension allows to show you a "table of content" generated by Github project README or WIKI.
JavaScript
66
star
19

larabbs-weapp

CSS
64
star
20

laravel-taggable

Taggable Trait for using tag inside Laravel Eloquent models, with Baum's Nested Set pattern support.
PHP
54
star
21

baidu-translate-ios-sdk

百度翻译 iOS SDK (非官方)
Objective-C
46
star
22

github-menu-back

Improvement of Github Top Menu
CSS
46
star
23

annotator

划词高亮功能
JavaScript
35
star
24

laracast_robot

A robot a download laracasts.com videos
JavaScript
29
star
25

zhihu

L07 Laravel 教程 - Laravel TDD 源码
PHP
28
star
26

administrator-demo

demo for https://github.com/summerblue/administrator
JavaScript
22
star
27

chrome-phphub-notifier

Notify you when interesting thing is happening at PHPHub.
JavaScript
18
star
28

http-class-for-php

HTTP Class for PHP , support for Both Curl and Socket
PHP
11
star
29

QiniuSdk_v7_demo

Little Demo Code for Qiniu v7.* SDK https://github.com/qiniu/objc-sdk
Objective-C
10
star
30

php-emoji-for-apns

a php helper function to send emoji encoded string to apns
PHP
10
star
31

lt-settler

为 《Laravel 入门教程》 https://laravel-china.org/laravel-tutorial/5.1/about 定制的 homestead box 打包脚本
Shell
10
star
32

Amr2Wav

A library that convert audio file format from amr to wav .
Objective-C
8
star
33

CS193pWinter-2013

Stanford CS193p Developing Applications for iOS Winter 2013 Source Code
Objective-C
4
star
34

laravel-quickstart-intermediate-5.1

Source code for http://laravel-china.org/docs/5.1/quickstart-intermediate, base on Laravel 5.1
PHP
3
star
35

voicecloud_with_amr2wav_demo

此项目是 `科大讯飞 - 语音识别` 转换 amr 音频格式的 DEMO.
Objective-C
3
star
36

ios-framework-comments

为 iOS 常用框架添加注释, 作为学习 iOS 开发的资料
Objective-C
2
star
37

nsscreencasts_robot

Video downloader for nsscreencasts.com
JavaScript
2
star
38

summerblue.me

Source code of the http://summerblue.me
ApacheConf
2
star
39

CS193pWinter-2011

Stanford CS193p Developing Applications for iOS Winter 2011 Source Code
Objective-C
1
star
40

weibo7.x

PHP
1
star
41

kindness-is-more-important

We value kindness and friendly more than anything.
1
star
42

baker-doc-chinese

A quick translation in Chinese for http://bakerframework.com/
1
star
43

githunt-x

fork from kamranahmedse/githunt add feature like: night mod, search, more time filter, next page ...
JavaScript
1
star
44

emoji-cheat-sheet

fork from https://github.com/WebpageFX/emoji-cheat-sheet.com , for PHPHub loading speed
HTML
1
star