小编sli*_*015的帖子

管理 2 个 git 用户 gpg 密钥并为每个用户选择 gpg 签名

我有 1 个 github 用户和另一个 gitlab 用户,我为每个用户创建了 1 个 gpg 密钥,因为我的电子邮件地址不同。

问题是git config --global user.signingkey每次我想提交到不同的 git 存储库时我都必须执行。

有没有办法可以为每个 git 用户管理我的 gpg 密钥?

git gpg-signature

7
推荐指数
3
解决办法
1591
查看次数

有没有办法在 krakend 端点配置中发送元数据?

我使用 Krakend 作为 API 网关,我的配置如下所示:

{
  "plugin": {
    "folder": "/etc/krakend/plugins/authenticator/",
    "pattern":".so"
  },
  "port": 8080,
  "extra_config": {
    "github_com/devopsfaith/krakend/transport/http/server/handler": {
      "name": "authenticator"
    }
  },

  "endpoints": [
    {
      "output_encoding": "no-op",
      "backend": [
        {
          "encoding": "no-op",
          "host": [
            "127.0.0.1:8080"
          ],
          "url_pattern": "/api/v1/address/{id}",
          "method": "GET"
        }
      ],
      "endpoint": "/api/v1/addresses/{id}",
      "method": "GET"
    }
  ],

  "name": "gateway",
  "timeout": "30s",
  "version": 2
}
Run Code Online (Sandbox Code Playgroud)

我想为每个端点传递一些元数据并在我的预定义插件中访问它。在这种情况下authenticator插件。

go api-gateway krakend

7
推荐指数
1
解决办法
401
查看次数

使 jwt 编码更快

我有一个/token正在使用password授权的端点。因为它对JWT令牌进行编码,所以它具有大约 1 秒的高延迟。有没有办法让 JWT 签名更快?

我正在使用 Go 与github.com/dgrijalva/jwt-go图书馆。

package main

import (
    "crypto/rsa"
    "git.snappfood.ir/golang/framework/assert"
    "io/ioutil"
    "time"

    
    "github.com/dgrijalva/jwt-go"
    "github.com/sirupsen/logrus"
)

var (
    private *rsa.PrivateKey
    public  *rsa.PublicKey
)

func main() {
    var err error
    var priv, pub []byte
    pub, err = ioutil.ReadFile("public.pem")
    if err!=nil{
        panic(err)
    }
    priv, err = ioutil.ReadFile("private.pem")
    if err!=nil{
        panic(err)
    }

    public, err = jwt.ParseRSAPublicKeyFromPEM(pub)
    if err!=nil{
        panic(err)
    }

    private, err = jwt.ParseRSAPrivateKeyFromPEM(priv)
    if err!=nil{
        panic(err)
    }

    data := map[string]interface{}{
        "jti": …
Run Code Online (Sandbox Code Playgroud)

go jwt jwt-go

6
推荐指数
1
解决办法
181
查看次数

在 golang 中为 proto buf 类型编写自定义 Marshall 和 Unmarshaller

我有自己编写的 Marshall 和 Unmarshaller 的自定义类型,问题是我想使用 protobuf 做同样的事情

我只是想使用 protobuf 实现相同的功能,这样我就可以实现我自己的 Marshall 和 Unmarshaller

syntax="proto3";

package main;

message NullInt64{
    bool Valid = 1;
    int64 Int64 = 2;
}
Run Code Online (Sandbox Code Playgroud)

如果 Valid 值为 false,则返回null字符串

type NullInt64 struct {
    Int64 int64
    Valid bool
}

// MarshalJSON try to marshaling to json
func (nt NullInt64) MarshalJSON() ([]byte, error) {
    if nt.Valid {
        return []byte(fmt.Sprintf(`%d`, nt.Int64)), nil
    }

    return []byte("null"), nil
}

// UnmarshalJSON try to unmarshal dae from input
func (nt *NullInt64) UnmarshalJSON(b …
Run Code Online (Sandbox Code Playgroud)

go protocol-buffers

5
推荐指数
1
解决办法
3429
查看次数

如何检查弹性搜索无痛参数中是否存在键?

无痛脚本映射参数中存在如何检查密钥。在下面的查询中,查询检查a.toString()键存在于参数中,我已经尝试了所有方法,但没有使它起作用。请帮我

映射:

"id": {
   "type": "long"
}
Run Code Online (Sandbox Code Playgroud)

查询:

{
  "query":{
    "bool":{
      "filter":[
        {
          "script": {
            "script": {
               "lang": "painless",
               "params": {
                 "29232":2541,
                 "minDistance": 0
               },
               "source": "def a=doc['id'].getValue();double distance=params[a.toString()]; return distance <= 1000 && distance >= params['minDistance']"
            }
          }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

elasticsearch elasticsearch-dsl elasticsearch-painless

5
推荐指数
1
解决办法
220
查看次数