Is there any REST API from BitBucket, which can be called from a GoLang so that it will create a new REPOSITORY. I can fetch the details of existing but not able to create a new one. Remember CURL is not requirement. Kindly help, stuck from some time into it. Is there any way do it via JAVA as well? If Java can do, then I think GoLang should be able to. Suggest!
如何使用GOLang通过调用REST API在BitBucket中创建REPOSITORY
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议
感谢您的意见,我们尽快改进~
BitBucket中是否有任何REST API,可以从GoLang中调用它,以便它将创建一个新的REPOSITORY。 我可以获取现有的详细信息,但无法创建新的详细信息。 请记住,CURL不是必需的。 请随时帮忙。 还有通过JAVA进行的任何方法吗? 如果Java可以做到,那么我认为GoLang应该可以。 建议! p> div>
- 写回答
- 好问题 提建议
- 追加酬金
- 关注问题
微信扫一扫
分享- 邀请回答
2条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
douzheyo2617 2018-01-23 08:14最佳回答 专家已采纳Thanks for Help guys! Yes, I am able to resolve this issue,with a colleague pointing out the mistake. Things required: 1. You should be having complete access for the bitBucket. 2. You should have correct URL where to connect with for the REST API. Note: REST API url is different than that of direct URL and get the versions Correct.
Go Code for same is::
import ( "encoding/json" "bytes" "fmt" "io/ioutil" "net/http" ) func main() { url:=fmt.Sprintf("https://<Server BitBucket>/rest/api/1.0/projects/<PROJECT WHERE REPO TO BE CREATED>/repos"); jsonData := map[string]string{"name":"<REPONAME>","scmID":"git","forkable":"true"} jsonValue,_:=json.Marshal(jsonData) req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue)) req.Header.Set("Content-Type", "application/json") req.SetBasicAuth("<USERNAME>", "<PASSWORD>") fmt.Println("++",req) client := &http.Client{} resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() fmt.Println("response Status:", resp.Status) fmt.Println("response Headers:", resp.Header) body, _ := ioutil.ReadAll(resp.Body) fmt.Println("response Body:", string(body)) }
This will give the response as 201 and yes, it will be created!!
采纳该答案 已采纳该答案 专家已采纳评论解决 无用打赏举报微信扫一扫
分享评论登录 后可回复...
查看更多回答(1条)
报告相同问题?
提交
相关推荐 更多相似问题
- 2018-01-18 03:07回答 2 已采纳 Thanks for Help guys! Yes, I am able to resolve this issue,with a colleague pointing out the mista
- 2019-05-07 09:29回答 1 已采纳 Golang comes with native "net/http" package which you can use to request REST APIs
- 2019-02-21 09:41回答 1 已采纳 Golang has the abstraction of io.Reader which encapsulates almost anything that can be read in bin
- 2021-03-28 23:49K8sCat的博客 Docker 提供了一个与 Docker 守护进程交互的 API (称为Docker Engine API),我们可以使用官方...该部分会介绍如何使用 Golang + Docker API 进行管理本地的 Docker。 运行容器 第一个例子将展示如何运行容器,相当于 .
- 2019-06-20 15:05terrygmx的博客 本文是原创文章,以后我踩过的golang或python的坑,都会在此和大家分享,共同进步! url.Values 百度搜索出来的Post调用方式,无论是 http.PostForm方式: func post(){ resp, err := http.PostForm(...
- 2018-12-30 16:28微光@倾城的博客 原文发布于微信公众号 - Golang语言社区(Golangweb) 原文发表时间:2016-04-20 Convert JSON in to a useful struct. http://json2struct.mervine.net/ * 帮助到的点个赞,欢迎评论
- 2017-06-22 21:54回答 1 已采纳 syslog is a platform-specific service, so the Logrus syslog hook code has a special comment, calle
- 2019-03-26 22:34回答 1 已采纳 You're redeclaring the host variable locally (this is also called "shadowing") host := new(object
- 2019-03-27 05:59回答 1 已采纳 In the go code, you are using AES in GCM mode with 12 bytes of zero as IV, but in java code you ar
- 2018-05-08 15:46蜗牛^_^的博客 一、go-json-rest框架介绍go-json-rest(https://github.com/ant0ine/go-json-rest/)是基于net/http的一个小封装,可帮助轻松构建RESTful JSON API。它使用基于Trie的实现提供快速和可拓展的请求路由,帮助处理JSON...
- 2018-11-30 14:52权羊羊的博客 题主的服务器用的是golang程序,但是加密加签、解密验签用的是java的方法,目前调用都是用golang调用jar包,但是调用jar的话,jar包必须要有主函数,这样导致加密是一个jar包,解密是一个jar包,这样就有4个jar包。...
- 2018-09-20 00:05freewebsys的博客 以前有很多项目都是java写的,业务逻辑是用dubbo做的服务。 这部分是不可能重写了。但是要是使用golang开发新项目。...同时也可以使用 golang 做server服务,让java 程序去做client 调用。 非常非常帮的。
- 2017-10-22 23:10回答 1 已采纳 As cerise mentioned, it's just formatting error in the JSON file. Must quote all properties. The
- 2019-09-10 00:27回答 1 已采纳 To call the method from the type, you must pass a reflect.Value instance that provides the Foo obj
- 2014-03-07 10:38回答 1 已采纳 The net/http package already takes care of this for you. Once you call Serve (or more likely Liste
- 2017-03-05 17:08freewebsys的博客 1,关于consuldubbo的注册... ... ... 使用consul的好处是服务发现啥的都支持了。 可以使用域名进行负载均衡。 也是一个不错的 Server-Side Discovery Pattern 。2,启动consul服务,调用接口首先要在服务器安装一个c
- 2019-08-01 20:15runhua的博客 为了更好兼容Windows,有时候需要直接在Go程序里面去调用Windows系统的API,比如在Go程序里面直接控制Windows窗口。 二、环境搭建 Windows下GO的下载、安装和配置 Windows下GO的下载、安装和配置可参考: GO语言...
- 2020-10-04 16:42pbrong的博客 本文只对比Golang与Java的基本情况、基本使用、结构体函数及指针三块内容,下一篇文章会对比面向对象、异常处理、并发编程及垃圾回收的差异。
- 2019-03-09 22:45回答 2 已采纳 There are a couple of issues in this code, but the first, and the one you point out, is that the N
- 2020-10-05 17:25pbrong的博客 本文是Golang与Java对比的第二篇,主要对比Golang与Java在面向对象、异常处理、并发编程及垃圾回收方面的差异。
- 没有解决我的问题, 去提问