mindxdl--common--utils.go
// Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved.
// Package common define common utils
package common
import (
"errors"
"net/http"
"strconv"
)
// ConvertToUint64 convert string to uint64
func ConvertToUint64(ID string) (uint64, error) {
id, err := strconv.ParseUint(ID, BaseHex, BitSize64)
return id, err
}
// GetHTTPHandler new HTTPHandler with http client
// 1. client with http;
// 2. client with https one way auth;
// 3. client with https two way auth;
func GetHTTPHandler(enableHTTP bool, authMode string) (*HTTPHandler, error) {
// http auth
if enableHTTP {
return &HTTPHandler{
Client: new(http.Client),
}, nil
}
wc := GetWebCertUtil()
if wc == nil {
return nil, errors.New("cannot get https one/two way auth handler because cert util is nil")
}
client, err := wc.GetRequestClient(authMode)
if err != nil {
return nil, err
}
return &HTTPHandler{
Client: client,
}, nil
}
本文来自博客园,作者:易先讯,转载请注明原文链接:https://www.cnblogs.com/gongxianjin/p/16683180.html