GetContent returns the content of r, decoding it if necessary.
()
| 80 | |
| 81 | // GetContent returns the content of r, decoding it if necessary. |
| 82 | func (r *RepositoryContent) GetContent() (string, error) { |
| 83 | var encoding string |
| 84 | if r.Encoding != nil { |
| 85 | encoding = *r.Encoding |
| 86 | } |
| 87 | |
| 88 | switch encoding { |
| 89 | case "base64": |
| 90 | if r.Content == nil { |
| 91 | return "", errors.New("malformed response: base64 encoding of null content") |
| 92 | } |
| 93 | c, err := base64.StdEncoding.DecodeString(*r.Content) |
| 94 | return string(c), err |
| 95 | case "": |
| 96 | if r.Content == nil { |
| 97 | return "", nil |
| 98 | } |
| 99 | return *r.Content, nil |
| 100 | case "none": |
| 101 | return "", errors.New("unsupported content encoding: none, this may occur when file size > 1 MB, if that is the case consider using DownloadContents") |
| 102 | default: |
| 103 | return "", fmt.Errorf("unsupported content encoding: %v", encoding) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // GetReadme gets the Readme file for the repository. |
| 108 | // |
no outgoing calls