This commit is contained in:
Christine Dodrill 2015-02-13 12:42:42 -08:00
parent fa3142ca31
commit a63f68504a
7 changed files with 204 additions and 0 deletions

View File

@ -3,3 +3,4 @@ FROM xena/lapis:1.7.7.2
ADD init/oleg /seed/oleg
RUN mv /seed/oleg/olegdb.conf /oleg/db.conf
ADD init/oleg/runit/ /etc/service
ADD init/startup/ /etc/my_init.d

View File

@ -8,6 +8,7 @@ class extends lapis.Application
@include "controllers.go"
@include "controllers.resume"
@include "controllers.index"
@include "controllers.blog"
[contact: "/contact"]: =>
@title = "Contact"

View File

@ -0,0 +1,143 @@
Getting Started with Go
=======================
Go is an exciting language made by Google for systems programming. This article
will help you get up and running with the Go compiler tools.
System Setup
------------
First you need to install the compilers.
```console
$ sudo apt-get install golang golang-go.tools
```
`golang-go.tools` contains some useful tools that aren't part of the standard
Go distribution.
Shell Setup
-----------
Create a folder in your home directory for your Go code to live in. I use
`~/go`.
```console
$ mkdir -p ~/go/{bin,pkg,src}
```
`bin` contains go binaries that are created from `go get` or `go install`.
`pkg` contains static (`.a`) compiled versions of go packages that are not go
programs. `src` contains go source code.
After you create this, add
[this](https://github.com/Xe/dotfiles/blob/master/.zsh/go-completion.zsh) and
the following to your zsh config:
```sh
export GOPATH=$HOME/go
export PATH=$PATH:/usr/lib/go/bin:$GOPATH/bin
```
This will add the go compilers to your `$PATH` as well as programs you install.
Rehash your shell config (I use
a [`resource`](https://github.com/Xe/dotfiles/blob/master/.zsh/resource.zsh#L3)
command for this) and then run:
```console
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xena/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
```
This will verify that the go toolchain knows where the go compilers are as well
as where your `$GOPATH` is.
Testing
-------
To test the go compilers with a simple
[todo command](http://github,com/mattn/todo), run this:
```console
$ go get github.com/mattn/todo
$ todo add foo
$ todo list
☐ 001: foo
```
Vim Setup
---------
For Vim integration, I suggest using the
[vim-go](https://github.com/fatih/vim-go) plugin. This plugin used to be part
of the standard Go distribution.
To install:
1. Add `Plugin 'fatih/vim-go'` to the plugins part of your vimrc.
2. Run these commands:
```console
$ vim +PluginInstall +qall
$ vim +GoInstallBinaries +qall
```
This will install the go oracle and the go autocompletion daemon gocode as well
as some other useful tools that will integrate seamlessly into vim. This will
also run `gofmt` on save to style your code to the standard way to write Go
code.
Resources
---------
[Effective Go](https://golang.org/doc/effective_go.html) and the
[language spec](https://golang.org/ref/spec) provide a nice overview of the
syntax.
The Go [blog](http://blog.golang.org) contains a lot of detailed articles
covering advanced and simple Go topics.
[This page](https://golang.org/doc/#articles) has a list of past articles that
you may find useful.
The Go standard library is a fantastic collection of Go code for solving many
problems. In some cases you can even write entire programs using only the
standard library. This includes things like web application support, tarfile
support, sql drivers, support for most kinds of commonly used crypto, command
line flag parsing, html templating, and regular expressions. A full list of
the standard library packages can be found [here](http://godoc.org/-/go).
Variable type declarations will look backwards. It takes a bit to get used to
but makes a lot of sense once you realize it reads better left to right.
For a nice primer on building web apps with Go, codegangsta is writing a book
on the common first steps, starting from the standard library and working up.
You can find his work in progress book
[here](http://codegangsta.gitbooks.io/building-web-apps-with-go/).
Go has support for unit testing baked into the core language tools. You can
find information about writing unit tests [here](http://golang.org/pkg/testing/).
When creating a new go project, please resist the urge to make the folder in your
normal code folder. Drink the `$GOPATH` koolaid. Yes it's annoying, yes it's the
language forcing you to use its standard. Just try it. It's an amazingly useful
thing once you get used to it.
Learn to love godoc. Godoc lets you document code like
[this](https://gist.github.com/Xe/b973e30d81280899955d). This also includes an
example of the builtin unit testing support.

31
controllers/blog.moon Normal file
View File

@ -0,0 +1,31 @@
discount = require "discount"
lapis = require "lapis"
file = require "pl.file"
http = require "lapis.nginx.http"
oleg = require "lib/oleg"
util = require "lapis.util"
dir = require "pl.dir"
import render_html from require "lapis.html"
split = require "util"
class Blog extends lapis.Application
["blog.index": "/blog"]: =>
@doc = oleg.cache "caches", "blog-index", ->
local data
with io.open "static/markdown/blog.html", "r"
data = \read "*a"
data
render: true
["blog.post": "/blog/:name"]: =>
@name = util.slugify @params.name
@doc = oleg.cache "blogposts", @name, ->
local data
with io.open "blog/#{@name}.markdown", "r"
data = \read "*a"
discount data, "toc", "nopants", "autolink"
render: true

View File

@ -0,0 +1,18 @@
#!/bin/bash
set -e
cd /app/src/blog
IFS='
'
for file in *
do
title=$(head -n1 $file)
line=$(head -n4 $file | tail -n1)
linkname=$(echo $file | awk -F "." '{print $1}')
echo '<div class="post"><h2>'"$title"'</h2><p>'"$line"'...</p><a href="/blog/'"$linkname"'">Read More</a></div>' >> /app/src/static/markdown/blog.html
echo "generated info for $file"
done

5
util.moon Normal file
View File

@ -0,0 +1,5 @@
split = (s, delimiter) ->
result = {}
for match in (s..delimiter)\gmatch "(.-)"..delimiter
table.insert result, match
result

5
views/blog/index.moon Normal file
View File

@ -0,0 +1,5 @@
import Widget from require "lapis.html"
class UserInfo extends Widget
content: =>
raw @doc