网络自动化:从HTTP API到NETCONF接口的探索
1. 从Python到Go:与HTTP API交互
在使用Python与HTTP API交互后,我们将使用Go语言来探索RESTCONF接口。Go语言的 net/http 包可以帮助我们实现这一目标。
1.1 使用 net/http 与RESTCONF获取配置
以下是一个使用Go的 net/http 包来获取Cisco IOS XE设备完整原生配置的示例代码:
package main
import (
"crypto/tls"
"encoding/base64"
"fmt"
"io/ioutil"
"log"
"net/http"
)
// helper method to construct the expected format of
// the basic authentication string, encoded in base64
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}
// helper method to implement the error-checking pattern
func checkError(err error)
超级会员免费看
订阅专栏 解锁全文
55

被折叠的 条评论
为什么被折叠?



