core

package module
v0.0.0-...-36feab7 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 8 Imported by: 0

README

Open Social

This is a port of https://github.com/reecerussell/social-media.

Stack

  • Golang
  • ReactJS/Node
  • SQL Server
  • Google Cloud Platform

Development

To build and run this locally, you'll need both Docker and NodeJS installed.

Backend

By running docker-compose, all of the services will be spun up and exposed via the ingress, on port 80.

Before running the docker-compose command, ensure there is a CONNECTION_STRING environment variable, set with a connection string to a SQL Server instance. An example of a connection string is sqlserver://<username>:<password>@<host>?database=<database>.

$ docker-compose -f docker-compose.dev.yaml up
Frontend

NPM is used to start the frontend locally, exposing it on port 3000.

cd ui
npm start

Google Cloud Platform

Currently, this is built to use GCP storage buckets as a filestore for the media service. The media service uses an interface which can be implemented for other services, such as AWS or Azure.

Documentation

Index

Constants

View Source
const DefaultPort = "8080"

DefaultPort is the default port number to use if the PortEnvVar is not set.

View Source
const PortEnvVar = "PORT"

PortEnvVar is the name of the environment variable user to read the port value.

Variables

This section is empty.

Functions

func ChainMiddleware

func ChainMiddleware(base http.Handler, middleware ...Middleware) http.Handler

ChainMiddleware chains a list of middleware into one http.Handler.

func HealthCheckHandler

func HealthCheckHandler(healthChecks []HealthCheck) http.Handler

HealthCheckHandler returns a new http.Handler which handles health checks, using the given health checks.

func ReadConfig

func ReadConfig(filename string, config interface{}) error

ReadConfig unmarshals JSON from a file to config.

Types

type App

type App struct {
	HealthChecks []HealthCheck

	HealthPath string
	// contains filtered or unexported fields
}

App pulls together components of a HTTP api, such as middleware, health checks and routing.

func NewApp

func NewApp() *App

NewApp returns a new instance of App.

func (*App) AddHealthCheck

func (app *App) AddHealthCheck(healthCheck HealthCheck)

AddHealthCheck adds a health check to the App.

func (*App) AddMiddleware

func (app *App) AddMiddleware(middleware Middleware)

AddMiddleware adds middleware to the App.

func (*App) Get

func (app *App) Get(path string, h http.Handler)

func (*App) GetFunc

func (app *App) GetFunc(path string, h http.HandlerFunc)

func (*App) Post

func (app *App) Post(path string, h http.Handler)

func (*App) PostFunc

func (app *App) PostFunc(path string, h http.HandlerFunc)

func (*App) Serve

func (app *App) Serve()

type BuildFunc

type BuildFunc func(ctn *Container) interface{}

BuildFunc is a function used to build a service.

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is a simple dependency injection container.

func NewContainer

func NewContainer() *Container

NewContainer returns a new Container.

func (*Container) AddService

func (ctn *Container) AddService(name string, builder BuildFunc)

AddService adds a new service definition to the container.

func (*Container) AddSingleton

func (ctn *Container) AddSingleton(name string, builder BuildFunc)

AddSingleton adds a new singleton service definition to the container.

func (*Container) GetService

func (ctn *Container) GetService(name string) interface{}

GetService attempts to resolve a service by name.

type ContextKey

type ContextKey string

ContextKey is a custom string type, used as a context value key.

type Handler

type Handler struct{}

Handler is a abstract handler which provides helpers to implementing handlers.

func (*Handler) Respond

func (*Handler) Respond(w http.ResponseWriter, data interface{})

Respond writes an OK status code, as well as writing data to the response as JSON.

func (*Handler) RespondError

func (*Handler) RespondError(w http.ResponseWriter, err error, status int)

RespondError writes an error to the response with the given status code.

type HealthCheck

type HealthCheck interface {
	Check(ctx context.Context) error
}

HealthCheck is used to check the status of a service.

type LoggingMiddleware

type LoggingMiddleware struct{}

LoggingMiddleware is middleware which logs all incoming requests.

func NewLoggingMiddleware

func NewLoggingMiddleware() *LoggingMiddleware

NewLoggingMiddleware returns a new instance of LoggingMiddleware.

func (*LoggingMiddleware) Handle

Handle returns a new http.Handler which logs all requests.

type Middleware

type Middleware interface {
	Handle(h http.Handler) http.Handler
}

Middleware is a http.Handler used as an intermediate step before handling a base handler.

type ServiceConfig

type ServiceConfig struct {
	Singleton bool
	Build     BuildFunc
}

ServiceConfig represents a service within the Container.

Directories

Path Synopsis
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
mock/auth
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
mock/media
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
mock/users
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
cmd
media/mock/repository
Package repository is a generated GoMock package.
Package repository is a generated GoMock package.
posts/mock/provider
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
posts/mock/repository
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
users/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
users/mock/provider
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
users/mock/repository
Package repository is a generated GoMock package.
Package repository is a generated GoMock package.
gcp
database
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
media
Package media is a generated GoMock package.
Package media is a generated GoMock package.

Jump to

Keyboard shortcuts

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