func (artifact *Artifact) Message() *rpc.Artifact {
	return &rpc.Artifact{
		Name:       artifact.Name(),
		MimeType:   artifact.MimeType,
		SizeBytes:  artifact.SizeInBytes,
		Hash:       artifact.Hash,
		CreateTime: timestamppb.New(artifact.CreateTime),
		UpdateTime: timestamppb.New(artifact.UpdateTime),
	}
}
Message returns an RPC message representing the artifact.
package models
import (
	"fmt"
	"strings"
	"time"
	"github.com/apigee/registry/rpc"
	"github.com/apigee/registry/server/registry/names"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/types/known/timestamppb"
)
type Artifact struct {
	Key         string    `gorm:"primaryKey"`
	ProjectID   string     
	ApiID       string     
	VersionID   string     
	SpecID      string     
	ArtifactID  string     
	CreateTime  time.Time  
	UpdateTime  time.Time  
	MimeType    string     
	SizeInBytes int32      
	Hash        string     
}
func NewArtifact(name names.Artifact, body *rpc.Artifact) (artifact *Artifact, err error) {
	now := time.Now().Round(time.Microsecond)
	artifact = &Artifact{
		ProjectID:  name.ProjectID(),
		ApiID:      name.ApiID(),
		VersionID:  name.VersionID(),
		SpecID:     name.SpecID(),
		ArtifactID: name.ArtifactID(),
		CreateTime: now,
		UpdateTime: now,
		MimeType:   body.GetMimeType(),
	}
	if body.GetContents() != nil {
		contents := body.GetContents()
		if strings.Contains(artifact.MimeType, "+gzip") && len(contents) > 0 {
			contents, err = GUnzippedBytes(contents)
			if err != nil {
				return nil, status.Error(codes.InvalidArgument, err.Error())
			}
		}
		artifact.SizeInBytes = int32(len(contents))
		artifact.Hash = hashForBytes(contents)
	}
	return artifact, nil
}
func (artifact *Artifact) Name() string {
	switch {
	case artifact.SpecID != "":
		return fmt.Sprintf("projects/%s/locations/%s/apis/%s/versions/%s/specs/%s/artifacts/%s",
			artifact.ProjectID, names.Location, artifact.ApiID, artifact.VersionID, artifact.SpecID, artifact.ArtifactID)
	case artifact.VersionID != "":
		return fmt.Sprintf("projects/%s/locations/%s/apis/%s/versions/%s/artifacts/%s",
			artifact.ProjectID, names.Location, artifact.ApiID, artifact.VersionID, artifact.ArtifactID)
	case artifact.ApiID != "":
		return fmt.Sprintf("projects/%s/locations/%s/apis/%s/artifacts/%s",
			artifact.ProjectID, names.Location, artifact.ApiID, artifact.ArtifactID)
	case artifact.ProjectID != "":
		return fmt.Sprintf("projects/%s/locations/%s/artifacts/%s",
			artifact.ProjectID, names.Location, artifact.ArtifactID)
	default:
		return "UNKNOWN"
	}
}