Skip to content
forked from suborbital/vektor

Build production-grade web services quickly

License

Notifications You must be signed in to change notification settings

agilebits/vektor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo_transparent

Intro

Vektor enables development of modern web services in Go. Vektor is designed to simplify the development of web APIs by eliminating boilerplate, using secure defaults, providing plug-in points, and offering common pieces needed for web apps. Vektor is fairly opinionated, but aims to provide flexibility in the right places.

Background

We see Go as the best language to build web APIs and rich backend services, and so Vektor's Go components are all focused on building those things.

Vektor consists of components that can be used to help you build your web apps and services. Vektor components can be used alone or together. Below is a list of in-development and planned components.

In development:

Vektor API (beta)

The vk component is central to Vektor. It helps to quickly build production-ready API services with Go. It includes secure-by-default settings such as built-in LetsEncrypt, lots of customizability, and helpers galore. It will soon integrate with Suborbital's Hive job scheduler to allow performing more complex and performance-oriented work. vk enables minimal-boilerplate servers with an intuitive wrapper around the most performant HTTP router, httprouter.

Vektor Logger (beta)

vlog is a low-effort logging package that will allow for structured or text-based logging, that will easily work with popular third-party logging systems.

Planned:

Vektor Authentication

The vauth component will provide an authentication library for service-service authentication (such as between vk services) as well as client-server authentication that can be extended to fit any need including end-user authentication.

Getting started

Creating a vk server is extremely simple:

import "github.com/suborbital/vektor/vk"

server := vk.New(
	vk.UseAppName("Vektor API Server"),
	vk.UseDomain("vektor.example.com"),
)

This will configure a server that sets up a LetsEncrypt certificate for vektor.example.com by serving content on :443 and the ACME challenge server on :80. Other options are available, see the full documentation for details.

To serve something, you'll need a handler:

type PingResponse struct {
	Ping string `json:"ping"`
}

func HandlePing(r *http.Request, ctx *vk.Ctx) (interface{}, error) {
	ctx.Log.Info("ping!")

	return PingResponse{Ping: "pong"}, nil
}

As you can see, handler functions don't actually concern themselves with responding to a request, rather just returning some data. vk is designed to handle the specifics of the HTTP response for you, all you need to do is return (interface{}, error). Vektor handles the returned data based on a simple set of rules. The simplest form is this: Want to respond with JSON? Just return a struct. To control exactly how the response behaves, check out the Response and Error types.

Mounting handlers to the server is just as easy:

server.GET("/ping", HandlePing)

And finally, start your server:

if err := server.Start(); err != nil {
	log.Fatal(err)
}

That's just the beginning! Vektor includes powerful features like composable middleware, route groups, some handy built-in helpers, and more.

To learn everything Vektor can do, visit the guide.

Copyright Suborbital contributors 2020

About

Build production-grade web services quickly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.5%
  • Makefile 0.5%