Code Monkey home page Code Monkey logo

apic's Introduction

API调用工具

快速调用第三方接口

用法

先定义结构体,在结构体中定义api路径、参数,如果需要鉴权也可以统一处理。

type RandMusicApi struct {
	*apic.Apic
}

func (m *RandMusicApi) Url() string {
	return "https://api.uomg.com"
}

func (m *RandMusicApi) Path() string {
	return "/api/rand.music"
}

func (m *RandMusicApi) Query() url.Values {
	u := url.Values{}
	u.Add("sort", "热歌榜")
	u.Add("format", "json")

	return u
}

func (m *RandMusicApi) HttpMethod() apic.HttpMethod {
	return apic.GET
}

func (m *RandMusicApi) Debug() bool {
	return true
}

使用方法

使用 apic.Init().CallApi(musicApi, nil) 请求接口,可以在请求自定义参数,请求结果在api返回数据中处理

musicApi := &apic.ApiId{
    Name:   "music",
    Client: &RandMusicApi{},
}

api, err := apic.Init().CallApi(musicApi, nil)
if err != nil {
    log.Panicln(err.Error())
    return
}

apic's People

Contributors

wonli avatar

Watchers

 avatar

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.