dittofunc
HTTP server implementation of Ditto https://github.com/juanvillacortac/ditto code generation.
Usage
// main.go
package main
import (
"flag"
"log"
"net/http"
"github.com/ethanthatonekid/dittofunc/ditto/httpserver/ditto"
)
var origin = "http://localhost:8080"
var owner = "juanvillacortac"
var repo = "ditto"
var path = "/examples/angular/config.yml"
var ref = "main"
var token string
func main() {
flag.StringVar(&origin, "origin", origin, "Ditto origin")
flag.StringVar(&owner, "owner", owner, "GitHub owner")
flag.StringVar(&repo, "repo", repo, "GitHub repo")
flag.StringVar(&path, "path", path, "GitHub path")
flag.StringVar(&ref, "ref", ref, "GitHub ref")
flag.StringVar(&token, "token", token, "GitHub token")
flag.Parse()
// Create a new client.
client := ditto.New(*http.DefaultClient, origin)
// Create a new query.
q := ditto.NewGenQuery(token, owner, repo, path, ref)
// Execute the query.
generated, err := client.Gen(q)
if err != nil {
log.Fatalln(err)
}
// Print the generated code.
log.Println(generated)
}
# Spin up the server locally.
go run .
# Make a request to the server.
go run examples/hello_world/main.go -token=...
Server
The Ditto httpserver.Handler is a simple HTTP handler that receives a Ditto configuration file from GitHub and generates the code.
Requirements:
go run .
Deployment
Netlify
Netlify is a great option for hosting the server.
Visit the Netlify website and create an account.
Get started with a new site from GitHub.
Select the GitHub repository and branch.
Set the base directory to internal/netlify.
Ignore the build command and publish directory.
License
MIT