ReanGD/go-web-search

View on GitHub
proxy/content.go

Summary

Maintainability
A
0 mins
Test Coverage
package proxy

import (
    "crypto/sha512"

    "github.com/ReanGD/go-web-search/database"
)

// Content - proxy struct for database.Content
type Content struct {
    hash  string
    body  database.Compressed
    title string
}

// NewContent - create Content
func NewContent(body []byte, title string) *Content {
    hash := sha512.Sum512(body)
    return &Content{
        hash:  string(hash[:]),
        body:  database.Compressed{Data: body},
        title: title}
}

// GetContent - convert to content.Content
func (in *Content) GetContent(urlID int64) *database.Content {
    return &database.Content{
        URL:   urlID,
        Hash:  in.hash,
        Body:  in.body,
        Title: in.title}
}