All Projects → george518 → Ppgo_api_demo_gin

george518 / Ppgo_api_demo_gin

API接口应用Demo 基于Gin

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Ppgo api demo gin

Taco Api
🍉 Brazilian Table of Food Composition (TACO) - JSON API
Stars: ✭ 87 (-3.33%)
Mutual labels:  api, restful-api
Rest Api Example
RESTful Blog API in Lumen 5.2
Stars: ✭ 53 (-41.11%)
Mutual labels:  api, restful-api
Tinyme
A tiny php framework based on flight and medoo with restful api service
Stars: ✭ 28 (-68.89%)
Mutual labels:  api, restful-api
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (+772.22%)
Mutual labels:  api, restful-api
Spacex Api
🚀 Open Source REST API for SpaceX launch, rocket, core, capsule, starlink, launchpad, and landing pad data.
Stars: ✭ 8,973 (+9870%)
Mutual labels:  api, restful-api
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+774.44%)
Mutual labels:  api, restful-api
Ebook Building An Api Backend With Microprofile
Building an API Backend with MicroProfile
Stars: ✭ 53 (-41.11%)
Mutual labels:  api, restful-api
Go Gin Example
An example of gin
Stars: ✭ 4,992 (+5446.67%)
Mutual labels:  api, gin
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+11715.56%)
Mutual labels:  api, restful-api
Standards.rest
A collection of standards, specifications, etc. for HTTP API development.
Stars: ✭ 58 (-35.56%)
Mutual labels:  api, restful-api
Koa2 Api Scaffold
一个基于Koa2的轻量级RESTful API Server脚手架。
Stars: ✭ 694 (+671.11%)
Mutual labels:  api, restful-api
Parvula
An extremely simple & flexible CMS generated from flat files with a complete RESTful API —
Stars: ✭ 76 (-15.56%)
Mutual labels:  api, restful-api
Snake
🐍 一款小巧的基于Go构建的开发框架,可以快速构建API服务或者Web网站进行业务开发,遵循SOLID设计原则
Stars: ✭ 615 (+583.33%)
Mutual labels:  api, gin
E Commerce 2 django
Guest register, user register, user login, user logout, account home page, product view history, change password, reset password, change name, send activation email when register, resend activation email, add shipping address, add billing address, add nickname to the addresses, edit shipping address, edit billing address, view list of your addresses, reuse shipping addresses when order products, reuse billing addresses when ordeer products, show sales analytics if staff or admin only using -chart.js-, get analytics data with Ajax, receive marketing email, change if user will receive marketing email or not by admin, send contact message with Ajax, products list, product detail, download product detail as a PDF file, download digital product files -if the user purchased that digital product only-, orders list, list of digital products files, order detail, download order detail as a PDF file, verify order ownership with Ajax -to secure order detail page-, show cart products, add or remove product from cart, checkout page, thanks page when order placed successfully, add or reuse payment method, add or reuse payment method with Ajax, search products by title, search products by description, search products by price, search products by tag title, write tags for products -by admin only-, auto fill contact email, full name if user logged in.
Stars: ✭ 20 (-77.78%)
Mutual labels:  api, restful-api
Datafire
A framework for building integrations and APIs
Stars: ✭ 487 (+441.11%)
Mutual labels:  api, restful-api
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-45.56%)
Mutual labels:  api, restful-api
Pfsense fauxapi
REST based API interface for pfSense 2.3.x and 2.4.x to facilitate devops
Stars: ✭ 288 (+220%)
Mutual labels:  api, restful-api
Jianshu
仿简书nx+nodejs+nestjs6+express+mongodb+angular8+爬虫
Stars: ✭ 296 (+228.89%)
Mutual labels:  api, restful-api
Api Strategy
Equinor API Strategy
Stars: ✭ 56 (-37.78%)
Mutual labels:  api, restful-api
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-21.11%)
Mutual labels:  api, restful-api

PPGo_Api_Demo_Gin

什么东西?What?

本项目是一个关于gin框架的练习代码。 采用go+mysql实现一个API应用实例。 练习内容包括: 中间件使用、RESTFul路由创建、mysql数据库使用、静态资源加载、页面创建、配置文件读取等等。
Gin是用Golang实现的一种Web框架。基于httprouter,它提供了类似martini但更好性能(路由性能约快40倍)的API服务

安装方法

1、go get github.com/george518/PPGo_Api_Demo_Gin
2、创建mysql数据库,并将ppgo_api_demo_gin.sql导入
3、修改config/config.ini 配置数据库
4、运行 go build
5、运行 ./run.sh start|stop 帮助访问:http://your_host:8000

有什么价值?

作用一:可以作为Gin框架的练手项目
作用二:可以用来快速搭建Gin框架的API应用
如果感觉项目不错,请赐予star, :)

API调用示例

新增会员 POST

curl -X POST http://127.0.0.1:8000/v0/member?sign=ee14b34513697cd27e0e83e46b084580&ts=1508304821&app_key=1001&method=POST -d "login_name=george518&password=123456"

会员列表 GET

curl -X GET http://127.0.0.1:8000/v0/member?page=1&page_size=4&sign=ee14b34513697cd27e0e83e46b084580&ts=1508304821&app_key=1001&method=GET

会员详情 GET

curl -X GET http://127.0.0.1:8000/v0/member/1?sign=ee14b34513697cd27e0e83e46b084580&ts=1508304821&app_key=1001&method=GET

编辑会员 PUT

curl -X PUT http://127.0.0.1:8000/v0/member/1?sign=ee14b34513697cd27e0e83e46b084580&ts=1508304821&app_key=1001&method=PUT -d "login_name=haodaquan&password=1234" 

删除会员 DELETE

curl -X DELETE http://127.0.0.1:8000/v0/member/4?sign=ee14b34513697cd27e0e83e46b084580&ts=1508304821&app_key=1001&method=DELETE

可以在middlewares/auth.go中修改超时验证。

//时差两秒返回无权 注意修改
time_check, _ := strconv.Atoi(ts)
if (now - int64(time_check)) > 100000000000 {
    noAuth(c, "Time out")
    return
}

PHP调用接口代码示例

<?php
/************************************************************
** @Description: PPGo_Api_Demo_Gin API调用DEMO for PHP
** @Author: haodaquan
** @Date:   2017-03-24 14:32:48
** @Last Modified by:   haodaquan
** @Last Modified time: 2017-10-11 13:49:57
*************************************************************/
defined('APP_KEY') OR define("APP_KEY","1001");
defined('APP_SECRET') OR define("APP_SECRET","haodaquan");
$url = "http://127.0.0.1:8000/v0/member/3";
$params["ts"] = time();
$params["method"] = "GET";
$res = http($url,$params,"GET",[],10,true);
print_r($res);
/**
 * [http 调用接口函数]
 * @Date   2016-07-11
 * @Author GeorgeHao
 * @param  string       $url     [接口地址]
 * @param  array        $params  [数组]
 * @param  string       $method  [GET\POST\DELETE\PUT]
 * @param  array        $header  [HTTP头信息]
 * @param  integer      $timeout [超时时间]
 * @param  boolean      $sign    [是否加密]
 * @param  string       $app_key [应用号]
 * @param  string       $app_secret [应用密码]
 * @return [type]                [接口返回数据]
 */
function http($url, $params, $method = 'GET', $header = array(), $timeout = 10,$sign=false,$app_key='',$app_secret='')
{
    $opts = array(
        CURLOPT_TIMEOUT => $timeout,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_HTTPHEADER => $header
    );
    $app_key    = $app_key ? $app_key : APP_KEY;
    $app_secret = $app_secret ? $app_secret : APP_SECRET;
    if($sign)
    {
        $ts = time();
        $check =[
            "app_key=" . $app_key,
            "app_secret=" . $app_secret,
            "method=" . $method,
            "ts=" . $ts];
        sort($check); 
        $url .= '?sign='.md5(join("&", $check)).
                '&ts='.$ts.'&app_key='.$app_key
                .'&method='.$method;
        // print_r($url);
    }
    /* 根据请求类型设置特定参数 */
    switch (strtoupper($method)) {
        case 'GET':
            if($params)
            {
               $opts[CURLOPT_URL] = $url . '?' . http_build_query($params); 
            }else
            {
                $opts[CURLOPT_URL] = $url;
            }
            break;
        case 'POST':
            $params = http_build_query($params);
            $opts[CURLOPT_URL] = $url;
            $opts[CURLOPT_POST] = 1;
            $opts[CURLOPT_POSTFIELDS] = $params;
            break;
        case 'DELETE':
            $opts[CURLOPT_URL] = $url;
            $opts[CURLOPT_HTTPHEADER] = array("X-HTTP-Method-Override: DELETE");
            $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
            $opts[CURLOPT_POSTFIELDS] = $params;
            break;
        case 'PUT':
            $opts[CURLOPT_URL] = $url;
            $opts[CURLOPT_POST] = 0;
            $opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
            $opts[CURLOPT_POSTFIELDS] = http_build_query($params);
            break;
        case 'PATCH':
            $opts[CURLOPT_URL] = $url;
            $opts[CURLOPT_POST] = 0;
            $opts[CURLOPT_CUSTOMREQUEST] = 'PATCH';
            $opts[CURLOPT_POSTFIELDS] = http_build_query($params);
            break;
        default:
            throw new Exception('不支持的请求方式!');
    }
  
    /* 初始化并执行curl请求 */
    $ch     = curl_init();
    curl_setopt_array($ch, $opts);
    $data   = curl_exec($ch);
    $error  = curl_error($ch);
    return $data;
}

联系我

qq:41352963

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].