Giter VIP home page Giter VIP logo

vektor's Introduction

Vektor has been deprecated. It is being absorbed into the E2 Core repo. No further releases will be published in this project. You can find the docs for this deprecated project in this repo.

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.

Components

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. 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.

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.

Copyright Suborbital contributors 2021.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.