chronicle

package module
v0.0.0-...-12c9185 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2018 License: MIT Imports: 4 Imported by: 5

README

chronicle

Go Report Card Build Status

Experimental golang microservices rest api without orm on news domain

Entities: Topics Stories

Database: postgres cache-server: redis

Authentication: JWS

Installation | Usage | License

chronicle is rest api microservices about news.

This project is only for experiment. There is much work to do for this project to be complete.

Installation (For Development)

  • git clone
  • set environt variables in .env (example below)
  • change config if necessary in config/development/config.yml
ENV=development

PORT=8000

PG_DATA_DIR=/home/path/to/your/postgresql-container-data

// leave this for production
PRODUCTION_JWT_SECRET=
PRODUCTION_CACHE_RESPONSE=

PRODUCTION_LOGGLYTOKEN=
PRODUCTION_LOGGLYHOST=

PRODUCTION_REDIS.HOST=
PRODUCTION_REDIS.PORT=
PRODUCTION_REDIS.PASSWORD=
PRODUCTION_REDIS.DB=
  • docker-compose up
  • create database "chronicle" on postgres
  • create database "chronicle-test" on postgres
  • run migration
make migration
  • run build
make
  • run chronicle

Usage

  • You will need access token to use the api
  • generate access token
make generate-token

License

MIT © [Adhitya Ramadhanus]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//StoryDraftStatus provide a uniform way to use draft status instead of literal string
	StoryDraftStatus = "Draft"
	//StoryDeletedStatus provide a uniform way to use deleted status instead of literal string
	StoryDeletedStatus = "Deleted"
	//StoryPublishStatus provide a uniform way to use publish status instead of literal string
	StoryPublishStatus = "Publish"
)

Functions

func Slugify

func Slugify(text string) string

Slugify return a human readable slug of a text

Types

type CacheKeyBuilder

type CacheKeyBuilder interface {
	BuildKey(obj interface{}) string
}

type CacheService

type CacheService interface {
	Set(key string, value []byte) error
	SetEx(key string, value []byte, expirationInSeconds time.Duration) error
	Get(key string) ([]byte, error)
}

type PagingOptions

type PagingOptions struct {
	Limit  int
	Offset int
	SortBy string
	Order  string
}

PagingOptions is a struct used as pagination option to get entities

type Stories

type Stories []Story

Stories short way to define array of story

type Story

type Story struct {
	ID       int
	Media    json.RawMessage
	Title    string
	Slug     string
	Excerpt  string
	Content  string
	Reporter string
	Editor   string
	Author   string
	Status   string
	Topics   Topics

	// stats
	Likes     int
	Shares    int
	Views     int
	CreatedAt time.Time
	UpdatedAt time.Time
}

Story is domain entity

type StoryFilterOptions

type StoryFilterOptions struct {
	Status string
	Topic  string
}

StoryFilterOptions struct used as parameter to filter story by status and its topic

type StoryRepository

type StoryRepository interface {
	Find(id int) (Story, error)
	FindBySlug(slug string) (Story, error)
	FindByStatus(status string, option PagingOptions) (stories Stories, storiesCount int, err error)
	FindByTopicAndStatus(topic int, status string, option PagingOptions) (stories Stories, storiesCount int, err error)
	All(option PagingOptions) (stories Stories, storiesCount int, err error)
	Insert(story Story) (createdStory Story, err error)
	Update(story Story) (updatedStory Story, err error)
	Delete(id int) error
}

StoryRepository provide an interface to get story entities

type Topic

type Topic struct {
	ID        int
	Name      string
	Slug      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Topic is domain entity

type TopicRepository

type TopicRepository interface {
	Find(id int) (Topic, error)
	FindBySlug(slug string) (Topic, error)
	All(option PagingOptions) (topics Topics, topicsCount int, err error)
	Insert(topic Topic) (createdTopic Topic, err error)
	Update(topic Topic) (updatedTopic Topic, err error)
	Delete(id int) error
}

TopicRepository provide an interface to get topic entities

type Topics

type Topics []Topic

Topics short way to define array of story

Directories

Path Synopsis
cmd
script
storage

Jump to

Keyboard shortcuts

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