Go——Artifactory的AQL查询以及json解析解决方案
生活随笔
收集整理的這篇文章主要介紹了
Go——Artifactory的AQL查询以及json解析解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
源代碼:https://gitee.com/shentuzhigang/mini-project/blob/master/jfrog-client-demo/artifactory/
官方SDK:http://github.com/jfrog/jfrog-client-go
AQL:https://www.jfrog.com/confluence/display/JFROG/Artifactory+Query+Language
解決方案
package artifactoryimport ("encoding/json""fmt""github.com/jfrog/jfrog-client-go/artifactory""github.com/jfrog/jfrog-client-go/artifactory/auth""github.com/jfrog/jfrog-client-go/config""github.com/jfrog/jfrog-client-go/utils/log""io/ioutil""os""testing""time" )type Range struct {StartPos int `json:"start_pos"`EndPos int `json:"end_pos"`Total int `json:"total"` }type Result struct {Repo string `json:"repo"`Name string `json:"name"` }type AqlResponse struct {Results []Result `json:"results"`Range Range `json:"range"` }func TestAQLAndJSON(t *testing.T) {var file *os.Filelog.SetLogger(log.NewLogger(log.INFO, file))rtDetails := auth.NewArtifactoryDetails()rtDetails.SetUrl("http://192.168.0.112:8081/artifactory/")rtDetails.SetUser("admin")rtDetails.SetPassword("123456")serviceConfig, err := config.NewConfigBuilder().SetServiceDetails(rtDetails).// Optionally overwrite the default HTTP timeout, which is set to 30 seconds.SetHttpTimeout(180 * time.Second).// Optionally overwrite the default HTTP retries, which is set to 3.SetHttpRetries(8).Build()if err != nil {fmt.Println(err)}rtManager, err := artifactory.New(serviceConfig)reader, err := rtManager.Aql("items.find()")if err != nil {t.Fail()return}bytes, err := ioutil.ReadAll(reader)if err != nil {t.Fail()return}res := &AqlResponse{}err = json.Unmarshal(bytes, res)if err != nil {t.Fail()return}fmt.Println(res) }參考文章
Go——連接 JFrog Artifactory 簡單測試
總結
以上是生活随笔為你收集整理的Go——Artifactory的AQL查询以及json解析解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Go——连接 JFrog Artifac
- 下一篇: Go——cron定时任务Demo