其他分享
首页 > 其他分享> > mindxdl--common--utils.go

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
}

标签:return,err,nil,--,utils,client,go,http,HTTPHandler
来源: https://www.cnblogs.com/gongxianjin/p/16683180.html