hexlink

package module
v0.0.0-...-8313ac8 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 13 Imported by: 0

README

A URL Shortening service with a hexagonal architecture written in Go

Examples

Shortening a URL
Send a Post Request to /api/shorten With a json body like:
{
"url": "http://www.google.com"
}
Note: The "http://" in the url is important TODO: improve this with http validation/autocorrection

Docker Commands

# Creating an Image
docker build -t nevzh/hexlink
docker run nevzh/hexlink
docker push nevzh/hexlink

# Using Docker Compose
docker compose up
[URL]/[code]
www.hexli.nk/DcJltl3MR # Not a Real URL 

OpenAPI Generation

The OpenAPI Specification (OAS) defines a standard, language-agnostic Hexlink uses OAS 3.0. oapi-codegen is used to generate types from the provided specification. We want to use go-kit to implement our server. However, I couldn't find a publicly available, well documented, and supported code generator for OpenAPI that supports go-kit.

Not all auto-generated types will be used. I expect to refine the process and utilization of both go kit and open api.

Generating Types from specification
  1. Ensure that the hexlink-schema submodule is the desired version.
  2. Install oapi-codegen
  3. Ensure that go binaries are included in your path
  4. oapi-codegen --config=codegen.cfg.yml hexlink-schema/hexlink.yaml

TODO:

  • Improve App Scalability
  • Improve ID Generation
  • Improve ID Management
  • Write a front end

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHttpServer

func NewHttpServer(ctx context.Context, endpoints Endpoints) http.Handler

Types

type BatchError

type BatchError struct {
	Code   string `json:"code"`
	Reason string `json:"reason"`
}

type CreateRedirectRequest

type CreateRedirectRequest struct {
	Url string `json:"url,omitempty"`
}

type CreateRedirectResponse

type CreateRedirectResponse struct {
	Code string `json:"code,omitempty"`
}

type CreateRedirectsRequest

type CreateRedirectsRequest struct {
	Urls []string `json:"urls"`
}

type CreateRedirectsResponse

type CreateRedirectsResponse struct {
	Successful []t.Redirect `json:"successful"`
	Failed     []BatchError `json:"failed"`
}

type Endpoints

type Endpoints struct {
	// Create a Batch of Redirects
	CreateRedirects endpoint.Endpoint
	// Query a Batch of Codes
	QueryRedirects endpoint.Endpoint
	// Resolve a Single Code
	GetRedirect endpoint.Endpoint
	// Shorten a Single URL
	CreateRedirect endpoint.Endpoint
}

func MakeEndpoints

func MakeEndpoints(s shortener.RedirectService) Endpoints

type GetRedirectRequest

type GetRedirectRequest struct {
	Code string `json:"code,omitempty"`
}

type GetRedirectResponse

type GetRedirectResponse struct {
	Url string `json:"url,omitempty"`
}

type LoggingMiddleware

type LoggingMiddleware struct {
	Logger log.Logger
	Next   shortener.RedirectService
}

func (LoggingMiddleware) Find

func (mw LoggingMiddleware) Find(code string) (output *t.Redirect, err error)

func (LoggingMiddleware) Store

func (mw LoggingMiddleware) Store(redirect *t.Redirect) (output string, err error)

type QueryRedirectsRequest

type QueryRedirectsRequest struct {
	Codes []string `json:"codes"`
}

type QueryRedirectsResponse

type QueryRedirectsResponse struct {
	Successful []t.Redirect `json:"successful"`
	Failed     []BatchError `json:"failed"`
}

type ServerError

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

func (ServerError) Error

func (err ServerError) Error() string

func (ServerError) StatusCode

func (err ServerError) StatusCode() int

Directories

Path Synopsis
cmd
repository
Package types provides primitives to interact with the openapi HTTP API.
Package types provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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