go
fengfanghuang
huangfangfeng.github.io
展开
-
在gin框架中使用sockjs-go
在gin框架中使用sockjs-go原创 2022-08-09 18:25:54 · 327 阅读 · 0 评论 -
[bug]:记一个k8s client-go leaderelection的bug
环境:k8s 1.17.2申请租约后,进程异常结束没有正常释放租约leaderelection.go:308] Failed to release lock: Lease.coordination.k8s.io "go-demo" is invalid: spec.leaseDurationSeconds: Invalid value: 0: must be greater than 0源码:client-go/leaderelection.go at v0.17.2 · kuberne原创 2021-12-31 09:51:24 · 370 阅读 · 0 评论 -
k8s leaderelection
const ( LEASELOCKNAME = "tes" LEASELOCKNAMESPACE = "kube-system")func main () { LeaseLockID = uuid.New().String() client.InitClientSet() run := func(ctx context.Context) { // 添加运行逻辑代码 klog.Info("Controller loop...") select{}.原创 2021-12-16 20:55:08 · 612 阅读 · 0 评论 -
go的gin框架从请求中获取参数
type Parms struct { Weight string `json:"weight"`}func HelloWorld(ctx *gin.Context) { id := ctx.Param("id") //取得URL中参数 name := ctx.Query("name") //查询请求URL后面的参数 sex := ctx.DefaultQuery("sex", "女") .原创 2021-12-16 15:24:53 · 644 阅读 · 0 评论 -
k8s资源定义yaml转结构体
import ( "encoding/json" "io/ioutil" v3 "github.com/projectcalico/libcalico-go/lib/apis/v3" ffmt "gopkg.in/ffmt.v1" yaml2 "k8s.io/apimachinery/pkg/util/yaml") logrus.Printf("parse gnp yaml:%s ", fp) data, err := ioutil.ReadFile(fp) if err !=.原创 2021-12-14 17:16:01 · 509 阅读 · 0 评论 -
golang http
import ( "bytes" "encoding/json" "io" "io/ioutil" "net/http" "time")func Get(url string) string { client := &http.Client{Timeout: 5 * time.Second} resp, err := client.Get(url) if err != nil { panic(err) } defer resp.Body.Close() var .原创 2021-11-26 14:36:32 · 942 阅读 · 0 评论 -
k8s Patch
// annotation nodefunc AnnotaClusterNodes(nodeName string, annotationKey string, annotationNewValue string) error { node, err := K8sClientSet.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{}) if err != nil { return err } annotations := node.Annot.原创 2021-11-26 14:33:05 · 503 阅读 · 0 评论 -
k8s Informer(node)
func NodeListWatch() { fmt.Printf("Start Node List Watch...\n") restClient := K8sClientSet.CoreV1().RESTClient() watchlist := cache.NewListWatchFromClient(restClient, "nodes", k8smetav1.NamespaceAll, fields.Everything()) _, controller := cache.NewIn..原创 2021-11-26 14:27:56 · 233 阅读 · 0 评论 -
k8s clientset
import ( "github.com/sirupsen/logrus" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd")var ( K8sClientSet kubernetes.Interface)func InitClientSet() { // init clientset for k8s operation // if kubeconf path is empty, Using the .原创 2021-11-26 14:24:13 · 222 阅读 · 0 评论 -
golang-cobra使用
Cobra提供简单的接口来创建强大的现代化CLI接口,比如git与go工具。Cobra同时也是一个程序, 用于创建CLI程序。 ▾ appName/ ▾ cmd/ root.go main.gomain.gopackage mainimport ( "fmt" "os" "{pathToYourApp}/cmd")func main() { cmd.Execute()}root.gopackage update原创 2021-11-17 10:10:31 · 319 阅读 · 0 评论 -
prometheus数据查询——golang
package prometheusimport ( "encoding/json" "fmt" "net/http" "net/url" "runtime/debug" "time" "gopkg.in/ffmt.v1")func GetPromResult(url string, result interface{}) error { httpClient := &http.Client{Timeout: 10 * time.Second} r, err := ..原创 2021-11-17 09:56:08 · 2529 阅读 · 0 评论 -
go build静态编译报错:/bin/ld: cannot find -ldl/-lpthread/-lc
缺少依赖库:yum install glibc-static原创 2021-07-02 13:44:02 · 848 阅读 · 0 评论 -
goland环境搭建(linux)
下载如版本:go1.14.4.linux-amd64.tar.gzwget -c https://studygolang.com/dl/golang/go1.14.4.linux-amd64.tar.gztar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz配置环境变量# vi /root/.bashrcexport GOROOT=/usr/local/goexport GOPATH=/root/goexport PATH=$PATH:原创 2021-06-26 16:11:32 · 526 阅读 · 0 评论