Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Adds wrapper for blob content #158

Closed
wants to merge 10 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions gitea/git_blob.go
Expand Up @@ -4,11 +4,36 @@

package gitea

import (
"bytes"
"encoding/json"

"code.gitea.io/gitea/modules/git"
)

// GitBlobResponse represents a git blob
richmahn marked this conversation as resolved.
Show resolved Hide resolved
type GitBlobResponse struct {
Content string `json:"content"`
type BlobResponse struct {
Content *BlobContentResponse `json:"content"`
Encoding string `json:"encoding"`
URL string `json:"url"`
SHA string `json:"sha"`
Size int64 `json:"size"`
}

type BlobContentResponse struct {
Blob *git.Blob
}

func (bc *BlobContentResponse) MarshalJSON() ([]byte, error) {
reader, err := bc.Blob.DataAsync()
if err != nil {
return nil, err
}
defer reader.Close()
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(reader)
if err != nil {
return nil, err
}
return json.Marshal(buf.Bytes())
}