2020年4月

graphql 有 Schema,Object,String,Int,Boolean 等元素组成。其中 Schema 包含 Query,Mutation,Subscription 三个 Object 类型的成员,对应 graphql 的三类操作。

var schema, _ = graphql.NewSchema(graphql.SchemaConfig{
    Query:    rootQuery, // 针对查询
    Mutation: rootMutation, // 针对写操作
    Subscription: rootSubscription, // 暂时没研究过,跟实时通讯相关
})

// 定义根 QueryObject
var rootQuery = graphql.NewObject(graphql.ObjectConfig{
    Name:        "RootQuery", // Object 的类型名,必须符合变量规则,不能包含空格
    Fields: graphql.Fields{ // 该对象所包含的字段列表
        "memos": &graphql.Field{
            Type: MemoType, // 类型是下面的自定义类型
            Args: graphql.FieldConfigArgument{
                "content": &graphql.ArgumentConfig{
                    Type: graphql.String,
                },
            },
            // 每个字段可以提供一个解析函数,用来告知 graphql 如何获取数据
            Resolve: func(p graphql.ResolveParams) (interface{}, error) {
                return nil, nil
            },
        },
    }
}

// 自定义Object
var MemoType = graphql.NewObject(graphql.ObjectConfig{
    Name:        "MemoType",
    Fields: graphql.Fields{
        "id": &graphql.Field{
            Name: "id",
            Type: graphql.Int,
        },
        "content": &graphql.Field{
            Name: "content",
            Type: graphql.String,
        },
    },
})
javascript调用

axios.post("/graphql", {
    "query": `mutation createMemo($content: String) { 
        createMemo(content: $content) {
            id
            content
        }
    }`,
    "variables": {
        content: "哈哈"
    }
}).then((resp) => {
    if (resp.status == 200 && !resp.data.errors) {
        console.log(resp.data.data)
    }
});

// 列出所有适配器
networksetup -listallnetworkservices

// 设置名字为 Ethernet 适配器 socks 为开启状态
networksetup -setsocksfirewallproxystate Ethernet on
// 设置名字为 Ethernet 适配器 socks 为关闭状态
networksetup -setsocksfirewallproxystate Ethernet off

// 修改适配器 socks 配置
networksetup -setsocksfirewallproxy Ethernet <domain> <port number> <authenticated> <username> <password>

authenticated: on off

package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    url := "https://api.64clouds.com/v1/getServiceInfo?veid=823669&api_key=private_xt5IHIYNAhuYxkFlvLpCWTGc"
    resp, err := http.Get(url)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    var data map[string]interface{}
    err = json.NewDecoder(resp.Body).Decode(&data)
    if err != nil {
        panic(err)
    }

    data_counter, ok := data["data_counter"].(float64)
    if !ok {
        return
    }
    v := data_counter / 1024.0 / 1024.0 / 1024.0
    fmt.Printf("%.2fGB/500.00GB\n", v)
}

./server_linux_amd64 -l :7777 -t localhost:7456 --mode fast3
./client_darwin_amd64 -l :7777 -r yueqiumao.com:7777 --mode fast3