Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New blog post, general updates #3

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
eudaimonia
==========

This runs <https://eudaimonia.io>.

Start a test instance:

```sh
go run main.go
```
5 changes: 5 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ h1,h2 {
margin-top: 2em;
}

img {
width: 100%;
margin: 1em;
}

pre {
background-color: #030303;
margin-bottom: 2em;
Expand Down
Binary file added images/blog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
const (
POSTS_DIR = "posts"
ASSETS_DIR = "assets"
IMAGES_DIR = "images"
TEMPLATES_DIR = "template"
)

Expand Down Expand Up @@ -75,6 +76,7 @@ func main() {
router.Delims("{{", "}}")
router.LoadHTMLGlob("./templates/*.tmpl.html")
router.Static("/assets", ASSETS_DIR)
router.Static("/images", IMAGES_DIR)
router.Use(gin.Logger())

// Register endpoints.
Expand Down
34 changes: 34 additions & 0 deletions posts/blog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Blog
====

This describes how this blog is constructed. Below is a description from the bottom up.

- Go is used to parse markdown files and generate HTML for posts. Each time a
page is requested it will perform this conversion according to the URL
path.

- Gin, a Go web framework, provides URL path routing, HTML templating, and
asset management.

- The application runs on Kubernetes, specifically the managed Kubernetes
offering from Linode, LKE.

- Traefik runs in Kubernetes and performs some network routing functions,
including:

- Providing NAT into the Kubernetes network for external traffic.
- Provisioning a Linode NodeBalancer to provision an external IP.

- AWS's Route53 service provides DNS that resolves to the NodeBalancer
external IP.

- Gandi.net provides an SSL certificate which is loaded into Kubernetes as a
Secret and terminated by Traefik as part of routing to the blog web
service.

[![Diagram of blog components](/images/blog.png)](/images/blog.png)

Terraform provisions everything except the blog itself, which is deployed
directly via a Kubernetes manifest from GitHub Actions.

See: <https://github.com/spacez320/eudaimonia>
50 changes: 27 additions & 23 deletions posts/go-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ These are notes on the Go programming language.

## Basics

- Each Go file declares a package.
- Style is enforced by the `go fmt` tool. Go expects certain styling to
compile.
- Each Go file declares a package.
- All Go programs have a main function in a main package.
- Uppercase methods are public and exportable, lowercase methods are private.
- Go constructs strings from **runes**, which are unicode characters. Unicode
Expand All @@ -24,10 +24,12 @@ Go source is compiled and executed from a `GOPATH`.
go install project

Go dependencies are done with Go Modules. Dependencies will be detected within
their use in code and then automatically downloaded.
their use in code and then automatically included (but may need to be
downloaded).

cd ./project
go mod init project
go get <package>
go mod tidy

Projects with a `main` package and a `main.go` file can be directly executed.
Expand All @@ -36,8 +38,8 @@ Projects with a `main` package and a `main.go` file can be directly executed.

## Variables

Go has static types with hinting. You can explicitly declare types, or you can
have Go figure it out using `:=`.
Go has static types with hinting. You can explicitly declare types or you can
have Go figure it out.

The following are equivalent:

Expand Down Expand Up @@ -77,7 +79,7 @@ The `_` variable can be used to throw away unneeded information.
Go will error on unused or over-declared variables.

All variables, when declared, are initialized to their "zero value," which
depends on the type (e.g., booleans get 'False' and integers get 0).
depends on the type (e.g., booleans get `false` and integers get `0`).

## Types

Expand All @@ -93,6 +95,19 @@ Type functions can also do some conversions. Each conversion creates a copy.

Some times include:

- **int** and **uint8** and **unint64** are integers.

- **float32** and **float64** are floating point types.

var pi float64 = 3.1415926
pi = float64(3.14159)

- **string** is a string.

- **bool** is a boolean. `!` is negation.

- Also **byte**.

- **iota** can create constant enumerations and is an auto incrementing value.

const (
Expand All @@ -111,17 +126,6 @@ Some times include:

fmt.Printf("%d %d %d", zero, four, eight) // Prints '0 4 8'.

- **float32** and **float64** are floating point types.

var pi float64 = 3.1415926
pi = float64(3.14159)

- **int** and **uint8** and **unint64** are integers.

- **bool** is a boolean. `!` is negation.

- Also **byte**.

- Also **error**--the built-in Go error type.

- The empty value in Go is `nil`.
Expand All @@ -135,7 +139,7 @@ Some times include:
bar int
}

s := &something(foo: "test")
s := &something{foo: "test"}
s.bar = 3

Both examples below will instantiate a struct with zero-values.
Expand All @@ -158,18 +162,18 @@ Strings can be indexed using array brackets and `:`.
astr[0:4]
astr[:4]

Looping over a string rune by rune:

for i, r := range astr {
fmt.Printf("%d %c\n", i, r)
}

The `range` keyword allows k/v iteration.

for _, r := range astr {
...
}

Looping over a string rune by rune:

for i, r := range astr {
fmt.Printf("%d %c\n", i, r)
}

Get string length with `len()`.

Strings in back quotes, \`, are interpreted literally. Double quotes, `""`,
Expand Down
3 changes: 2 additions & 1 deletion templates/index.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<body>
<div class="header">
<h1>eudaimonia.io</h1>
I use this space to write.
<p>I use this space to write.</p>
<p>This is me: <a href="https://github.com/spacez320">https://github.com/spacez320</a></p>
</div>
<div class="body">
<ul>
Expand Down