本文整理匯總了Golang中github.com/ccpaging/log4go.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: v1GetTags
func v1GetTags(repoSlice []RepoType) (tagSlice []TagInfo, e error) {
var client *http.Client
if *RegistryTLSNoVerify {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
for _, repo := range repoSlice {
// get tags for one repo
response, err := RegistryQuery(client, RegistryAPIURL+"/v1/repositories/"+string(repo)+"/tags")
if err != nil {
blog.Error(err)
if s, ok := err.(*HTTPStatusCodeError); ok {
blog.Error("Skipping Repo: %s, tag lookup status code %d", string(repo), s.StatusCode)
continue
}
return
}
//parse JSON output
var m map[TagType]ImageIDType
if e = json.Unmarshal(response, &m); e != nil {
return nil, e
}
var t TagInfo
t.Repo = repo
t.TagMap = m
tagSlice = append(tagSlice, t)
}
return
}
示例2: RegistryRequestWithToken
// RegistryRequestWithToken queries a Docker Registry that uses v1 Token Auth, e.g., Docker Hub.
func RegistryRequestWithToken(client *http.Client, URL string, dockerToken string) (response []byte, e error) {
var req *http.Request
req, e = http.NewRequest("GET", URL, nil)
if e != nil {
blog.Error(e)
return
}
req.Header.Set("Authorization", "Token "+dockerToken)
var r *http.Response
r, e = client.Do(req)
if e != nil {
blog.Error(e)
return
}
defer r.Body.Close()
if r.StatusCode != 200 {
e = &HTTPStatusCodeError{StatusCode: r.StatusCode}
return
}
response, e = ioutil.ReadAll(r.Body)
if e != nil {
blog.Error(e)
return
}
return
}
示例3: runAllScripts
func runAllScripts(imageID ImageIDType) (outMap map[string]interface{}, err error) {
//script name -> either byte array, or known types (e.g., ImageDataInfo)
outMap = make(map[string]interface{})
scripts := getScriptsToRun()
for _, script := range scripts {
//run script
output, err := script.Run(imageID)
if err != nil {
blog.Error(err, ": Error in running script: ", script.Name())
continue //continue trying to run other scripts
}
//analyze script output
switch script.Name() {
case PKGEXTRACTSCRIPT:
imageDataInfo, err := parsePkgExtractOutput(output, imageID)
if err != nil {
blog.Error(err, ": Error in parsing PkgExtractOuput")
return nil, err
}
outMap[script.Name()] = imageDataInfo
default:
//script name -> byte array
outMap[script.Name()] = output
}
}
return
}
示例4: ValidRepoName
// ValidRepoName verifies that the name of a repo is in a legal format.
func ValidRepoName(name string) bool {
if len(name) == 0 {
return false
}
if len(name) > 256 {
blog.Error("Invalid repo name, too long: %s", name)
return false
}
for _, c := range name {
switch {
case c >= 'a' && c <= 'z':
continue
case c >= 'A' && c <= 'Z':
continue
case c >= '0' && c <= '9':
continue
case c == '/' || c == '_' || c == '-' || c == '.':
continue
default:
blog.Error("Invalid repo name %s", name)
return false
}
}
return true
}
示例5: copy
func copy(src, dest string) {
// Read all content of src to data
data, err := ioutil.ReadFile(src)
if err != nil {
blog.Error(err, ": Error in reading from file: ", src)
return
}
// Write data to dest
err = ioutil.WriteFile(dest, data, 0755)
if err != nil {
blog.Error(err, ": Error in writing to file: ", dest)
return
}
}
示例6: Fail
// Fail prints an error message at blog.ERROR level and then quits with exit status ErrorExitStatus.
func Fail(arg0 interface{}, args ...interface{}) {
if len(args) == 0 {
blog.Error(arg0)
} else {
switch arg0.(type) {
case string:
blog.Error(arg0.(string), args...)
default:
blog.Error(arg0, args...)
}
}
blog.Close()
os.Exit(ErrorExitStatus)
}
示例7: PullImage
// PullImage performs a docker pull on an image specified by repo/tag.
// TODO: Detect if the pulled image has a different imageID than the value retrieved from
// metadata, and if so correct the metadata, or at least skip processing the image.
func PullImage(metadata ImageMetadataInfo) {
tagspec := RegistrySpec + "/" + metadata.Repo + ":" + metadata.Tag
apipath := "/images/create?fromImage=" + tagspec
blog.Info("PullImage downloading %s, Image ID: %s", apipath, metadata.Image)
config.BanyanUpdate("Pull", apipath, metadata.Image)
resp, err := DockerAPI(DockerTransport, "POST", apipath, []byte{}, XRegistryAuth)
if err != nil {
blog.Error(err, "PullImage failed for", RegistrySpec, metadata.Repo, metadata.Tag, metadata.Image)
}
if strings.Contains(string(resp), `"error":`) {
blog.Error("PullImage error for %s/%s/%s", RegistrySpec, metadata.Repo, metadata.Tag)
}
blog.Trace(string(resp))
return
}
示例8: jsonifyAndWriteToFile
func jsonifyAndWriteToFile(filenamePath string, data interface{}) (err error) {
b, err := json.MarshalIndent(data, "", "\t")
if err != nil {
blog.Error(err, ": Error in marshaling json")
return err
}
err = ioutil.WriteFile(filenamePath, b, 0644)
if err != nil {
blog.Error(err, ": Error in writing to file: ", filenamePath)
return err
}
return nil
}
示例9: CreateDirIfNotExist
func CreateDirIfNotExist(dir string) (err error) {
exists, err := DirExists(dir)
if err != nil {
blog.Error(err, ": Error while querying dir: ", dir)
return err
}
if !exists {
err = os.MkdirAll(dir, 0755)
if err != nil {
blog.Error(err, ": Error in creating dir: ", dir)
return err
}
}
return nil
}
示例10: WriteImageAllData
// WriteImageAllData writes image (pkg and other) data into file
func (f *FileWriter) WriteImageAllData(outMapMap map[string]map[string]interface{}) {
blog.Info("Writing image (pkg and other) data into file...")
for imageID, scriptMap := range outMapMap {
for scriptName, out := range scriptMap {
scriptDir := f.dir + "/" + trimExtension(scriptName)
err := fsutil.CreateDirIfNotExist(scriptDir)
if err != nil {
blog.Error(err, ": Error creating script dir: ", scriptDir)
continue
}
image := string(imageID)
if len(image) < 12 {
blog.Warn("Weird...Haven't seen imageIDs so small -- possibly a test?")
} else {
image = string(imageID)[0:12]
}
filenamePath := scriptDir + "/" + image
if _, ok := out.([]byte); ok {
f.format = "txt"
filenamePath += "-miscdata"
} else {
// by default it is json. But f.format could get overwritten at any point
// in the for loop if the output type is []byte, hence the (re)assignment
f.format = "json"
// NOTE: If we start using json for output other than imageData, change this
filenamePath += "-pkgdata"
}
f.writeFileInFormat(filenamePath, &out)
}
}
return
}
示例11: getTagsTokenAuthV1
func getTagsTokenAuthV1(repo RepoType, client *http.Client, indexInfo IndexInfo) (tagSlice []TagInfo, e error) {
tagSlice, e = lookupTagsTokenAuthV1(client, indexInfo)
if e != nil {
blog.Error(e, ": Error in looking up tags in dockerhub")
}
return
}
示例12: getRepos
// getRepos queries the Docker registry for the list of the repositories it is currently hosting.
// However, if the user specified a list of repositories, then getRepos() just returns that list
// of specified repositories and does not query the Docker registry.
func getRepos() (repoSlice []RepoType, err error) {
if len(ReposToProcess) > 0 {
for repo := range ReposToProcess {
repoSlice = append(repoSlice, repo)
}
return
}
if *RegistryProto == "v2" {
blog.Error("v2 registry search/catalog interface not yet supported in collector")
return
}
// a query with an empty query string returns all the repos
var client *http.Client
if *RegistryTLSNoVerify {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
return registrySearchV1(client, "")
}
示例13: lookupMetadataTokenAuthV1
// lookupMetadataTokenAuthV1 takes as input the imageID, and Docker Hub auth/index info,
// and it returns ImageMetadataInfo for that image by querying the indexed registry.
func lookupMetadataTokenAuthV1(imageID ImageIDType, client *http.Client, indexInfo IndexInfo) (
metadata ImageMetadataInfo, e error) {
blog.Info("Get Metadata for Image: %s", string(imageID))
URL := "https://" + indexInfo.RegistryURL + "/v1/images/" + string(imageID) + "/json"
response, e := RegistryRequestWithToken(client, URL, indexInfo.DockerToken)
if e != nil {
blog.Error(e, "Unable to query metadata for image: "+string(imageID))
return
}
// log.Print("metadata query response: " + string(response))
var m ImageStruct
if e = json.Unmarshal(response, &m); e != nil {
return
}
var creationTime time.Time
metadata.Image = string(imageID)
if creationTime, e = time.Parse(time.RFC3339Nano, m.Created); e != nil {
return
}
metadata.Datetime = creationTime
metadata.Size = m.Size
metadata.Author = m.Author
metadata.Checksum = m.Checksum
metadata.Comment = m.Comment
metadata.Parent = m.Parent
return
}
示例14: getReposTokenAuthV1
// getReposTokenAuthV1 validates the user-specified list of repositories against an index server, e.g., Docker Hub.
// It returns a list of IndexInfo structs with index info for each validated repository.
func getReposTokenAuthV1(repo RepoType, client *http.Client) (indexInfo IndexInfo, e error) {
_, _, BasicAuth, XRegistryAuth = GetRegistryURL()
URL := RegistryAPIURL + "/v1/repositories/" + string(repo) + "/images"
req, e := http.NewRequest("GET", URL, nil)
req.Header.Set("X-Docker-Token", "true")
if BasicAuth != "" {
req.Header.Set("Authorization", "Basic "+BasicAuth)
}
r, e := client.Do(req)
if e != nil {
blog.Error(e, ":getReposTokenAuthV1 HTTP request failed")
return
}
defer r.Body.Close()
if r.StatusCode != 200 {
e = &HTTPStatusCodeError{StatusCode: r.StatusCode}
return
}
dockerToken := r.Header.Get("X-Docker-Token")
if dockerToken == "" {
e = errors.New("lookup error for repo " + string(repo))
return
}
registryURL := r.Header.Get("X-Docker-Endpoints")
arr := strings.Split(registryURL, ",")
if len(arr) == 0 {
registryURL = ""
e = errors.New("lookup error for repo " + string(repo))
return
}
registryURL = strings.TrimSpace(arr[0])
indexInfo = IndexInfo{Repo: repo, DockerToken: dockerToken, RegistryURL: registryURL}
return
}
示例15: RemoveImages
// RemoveImages removes least recently pulled docker images from the local docker host.
func RemoveImages(PulledImages []ImageMetadataInfo, imageToMDMap map[string][]ImageMetadataInfo) {
numRemoved := 0
for _, imageMD := range PulledImages {
// Get all metadata (repo/tags) associated with that image
for _, metadata := range imageToMDMap[imageMD.Image] {
// basespec := RegistrySpec + "/" + string(t.Repo) + ":"
if ExcludeRepo[RepoType(metadata.Repo)] {
continue
}
blog.Debug("Removing the following registry/repo:tag: " + RegistrySpec + "/" +
metadata.Repo + ":" + metadata.Tag)
apipath := "/images/" + RegistrySpec + "/" + metadata.Repo + ":" + metadata.Tag
blog.Info("RemoveImages %s", apipath)
config.BanyanUpdate("Remove", apipath)
_, err := DockerAPI(DockerTransport, "DELETE", apipath, []byte{}, "")
if err != nil {
blog.Error(err, "RemoveImages Repo:Tag", metadata.Repo, metadata.Tag,
"image", metadata.Image)
}
numRemoved++
}
}
blog.Info("Number of repo/tags removed this time around: %d", numRemoved)
return
}