Giter Site home page Giter Site logo

clash-api's Introduction

clash api

本项目是 Clash RESTful API 的 golang 实现。我丢,搬砖活。

Introduction

Clash RESTful API 是一套控制 Clash 的一个途径,能获取 Clash 中的一些信息,同时也能控制 Clash 内部的配置。基于 API,可以打造自己的可视化操作部分,也是实现 Clash GUI 的重要组成部分。—— Clash doc

因为 new bing 需要用到香港节点,我平常也不用此节点,于是整了个自动切换脚本。开源 RESTful API 部分。

API

// 默认url为http://127.0.0.1:9090,如需修改,请调用此函数
func SetURL(URL string) {}

// 设置密钥(调用业务接口前必须调用此接口)
func SetSecret(sec string) {}
func SetSecretFromEnv(name string) error {}
func SetSecretFromFile(file string) error {}

// 监控请求日志
func GetLogs(level LogLevel) (chan *Log, error) {}

// 每秒推送一次,上下载流量
func GetTraffic(handler func(traffic *Traffic) (stop bool)) error {}

// 节点列表
func GetProxies() (map[string]*Proxies, error) {}

// 具体节点的信息
func GetProxyMessage(name string) (*Proxy, error) {}

// 测试具体节点的延时
func GetProxyDelay(name string, url string, timeout int) (*ProxyDelay, error) {}

// 切换节点
func SwitchProxy(selector, name string) error {}

// 获取配置
func GetConfig() (*Config, error) {}

// 设置配置
func SetConfig(port, socksPort int, redirPort string, allowLan bool, mode, logLevel string) error {}

// 应用配置(不会影响 external-controller 和 secret 的值)
func EnableConfig(path string) error {}

// PAC rules
func GetRules() ([]*Rule, error) {}

Example

package main

import (
	"fmt"
	"github.com/obgnail/clash-api/clash"
)

func main() {
	if err := clash.SetSecretFromFile("./secret.txt"); err != nil {
		panic(err)
	}

	proxies, err := clash.GetProxies()
	if err != nil {
		panic(err)
	}
	fmt.Println(proxies)
}

Processing

  • 支持 Meta (mihomo) 内核 API

    以最新 Meta Alpha 内核及 Metacubexd 的代码实现为准,Meta Wiki 为辅

clash-api's People

Contributors

obgnail avatar xxnuo avatar ijkzen 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.