goldblum

package module
v0.0.0-...-5066f2e Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

README

Goldblum

Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should.

Warning

Don't do this in production (or probably anywhere?). This is just a proof of concept. Seriously. It's not secure, it's not safe.

What is it?

A golang webserver that allows adding new endpoints and modifying the source code for old endpoints live!

Example screenshot

Why?

To see if I could.

How?

docker-compose up

This will give you an instance of Goldblum and a MySQL server. It may take a few minutes the first time to come up.

Navigate in your browser to http://localhost:8001/ to create your first endpoint.

Here's an easy one:

Set Method to GET and the endpoint to /helloworld and the code to:

package main

import (
    "fmt"
    "net/http"

    gb "github.com/transitorykris/goldblum"
)

const page = "<html><body><h1>Hello, World!</h1></body></html>"

func Handler(g *gb.Goldblum, w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, page)
}

Now navigate to http://localhost:8001/helloworld to test out your new endpoint.

Go ahead and head back to the editor and make a change to the endpoints source!

Tell me more

*gb.Goldblum

Your handler gets a sweet struct containing a connection to the database as well as a structured logger.

type Goldblum struct {
	DB  *sqlx.DB
	Log *logrus.Logger
}

License

Copyright 2017 Kris Foster

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Jeff Goldblum

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Response

func Response(w http.ResponseWriter, v interface{}, status int) error

Response is a nice wrapper for sending JSON responses

Types

type EmptyResponse

type EmptyResponse struct{}

EmptyResponse is used when we need no body

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is used when a json object needs to be returned with just an error

type Goldblum

type Goldblum struct {
	DB  *sqlx.DB
	Log *logrus.Logger
}

Goldblum is the the struct that gets passed to each handler with some goodies

type Handler

type Handler func(*Goldblum, http.ResponseWriter, *http.Request)

Handler is an HTTP handler created by the user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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