Help us shape the future of Go! Take the 2026 Go Developer Survey

comments

package
v0.54.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package comments implements flat, chronological comment threads on file/folder nodes (v0.6 "Çalışma" (Work) wave, migration 00020).

Access model (enforced by the caller/handler via acl.Resolver): anyone who can SEE a node (≥viewer) may read AND write comments on it; deleting a comment is author-or-admin (enforced HERE, since it depends on comment ownership, not node ACL). Rows are soft-deleted; hard removal rides the nodes FK CASCADE plus the trash purge hook.

Index

Constants

View Source
const MaxBodyLen = 5000

MaxBodyLen is the maximum comment length in runes (spec: 1..5000).

Variables

View Source
var (
	// ErrBadBody — empty (after trim) or over-length body → 400.
	ErrBadBody = errors.New("comments: body must be 1..5000 characters")
	// ErrNotFound — comment or node missing/soft-deleted → 404.
	ErrNotFound = errors.New("comments: not found")
	// ErrForbidden — delete by someone who is neither author nor admin → 403.
	ErrForbidden = errors.New("comments: forbidden")
)

Sentinel errors the handler maps to HTTP statuses.

Functions

func CanDelete

func CanDelete(c *model.NodeComment, user *model.User) bool

CanDelete reports whether user may delete comment c: the author or any admin account. Shared with the handler so list responses can stamp a per-row `can_delete` for the UI ("kendi yorumunda sil").

Types

type Service

type Service struct {
	Store db.Store
}

Service is the comment engine. Thin by design: validation + ownership rules here, SQL in db.Store, node-visibility ACL in the handler.

func New

func New(store db.Store) *Service

New constructs a Service.

func (*Service) Add

func (s *Service) Add(ctx context.Context, nodeID, userID int64, body string) (*model.NodeComment, error)

Add validates the body (1..5000 runes after trim) and inserts a comment by user on node. The caller must have verified node visibility already.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int64, user *model.User) (*model.NodeComment, error)

Delete soft-deletes a comment. Only the comment's author or an admin account may delete; anyone else gets ErrForbidden. A missing (or already deleted) comment yields ErrNotFound.

func (*Service) List

func (s *Service) List(ctx context.Context, nodeID int64) ([]*model.NodeComment, error)

List returns the live comments of a node, oldest first, author-joined. Never returns nil on success (empty slice instead) so the JSON encodes as [] rather than null.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL