Compare commits

...

4 Commits

Author SHA1 Message Date
AJ ONeal
ab12d4fec3 ref: swap 'go' is canonical, 'golang' is alias 2023-08-09 23:04:39 +00:00
AJ ONeal
e7fef765b1 ref: make 'go' canonical installer, not just alias 2023-08-09 23:04:07 +00:00
AJ ONeal
d30860c163 feat: add golang-essentials alias 2023-08-09 22:57:38 +00:00
AJ ONeal
98d2cd3af0 ref!(go): separate go from go-essentials for 1.21 2023-08-09 22:57:38 +00:00
11 changed files with 305 additions and 75 deletions

View File

@@ -1,5 +1,66 @@
#!/bin/pwsh
#!/usr/bin/env pwsh
echo "'go@$Env:WEBI_TAG' is an alias for 'golang@$Env:WEBI_VERSION'"
IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" }
curl.exe -fsSL "$Env:WEBI_HOST/golang@$Env:WEBI_VERSION" | powershell
if (!(Get-Command "go.exe" -ErrorAction SilentlyContinue))
{
& "$Env:USERPROFILE\.local\bin\webi-pwsh.ps1" go
# because we need git.exe to be available to golang immediately
$Env:PATH = "$Env:USERPROFILE\go\bin;$Env:USERPROFILE\.local\opt\go\bin;$Env:PATH"
}
# Special to go: re-run all go tooling builds
echo "Building go language tools..."
echo ""
echo godoc
& go install golang.org/x/tools/cmd/godoc@latest
echo ""
echo gopls
& go install golang.org/x/tools/gopls@latest
echo ""
echo guru
& go install golang.org/x/tools/guru@latest
echo ""
echo golint
& go install golang.org/x/lint/golint@latest
#echo ""
#echo errcheck
#& go install github.com/kisielk/errcheck
#echo ""
#echo gotags
#& go install github.com/jstemmer/gotags
echo ""
echo goimports
& go install golang.org/x/tools/cmd/goimports@latest
echo ""
echo gomvpkg
& go install golang.org/x/tools/cmd/gomvpkg@latest
echo ""
echo gorename
& go install golang.org/x/tools/cmd/gorename
echo ""
echo gotype
& go install golang.org/x/tools/cmd/gotype
echo ""
echo stringer
& go install golang.org/x/tools/cmd/stringer
echo ""
# literal %USERPROFILE% on purpose
echo 'Installed go "x" tools to GOBIN=%USERPROFILE%/go/bin'
echo ""
echo "Suggestion: Also check out these great productivity multipliers:"
echo ""
echo " - vim-essentials (sensible defaults for vim)"
echo " - vim-go (golang linting, etc)"
echo ""

View File

@@ -3,9 +3,7 @@ set -e
set -u
__run_go_essentials() {
WEBI__GO_ESSENTIALS='true'
export WEBI__GO_ESSENTIALS
if [ -z "${WEBI__GO_INSTALL-}" ]; then
if command -v go 2> /dev/null; then
"$HOME/.local/bin/webi" "golang@${WEBI_TAG}"
fi
@@ -75,6 +73,9 @@ __run_go_essentials() {
go "${my_install}" golang.org/x/tools/cmd/stringer@latest > /dev/null #2>/dev/null
echo ""
# literal $HOME on purpose
# shellcheck disable=SC2016
echo 'Installed go "x" tools to GOBIN=$HOME/go/bin'
printf '\n'
printf 'Suggestion: Also check out these great productivity multipliers:\n'

View File

@@ -1,11 +1,89 @@
---
title: Go (golang alias)
homepage: https://webinstall.dev/golang
title: Go
homepage: https://golang.org
tagline: |
Alias for https://webinstall.dev/golang
alias: golang
description: |
See https://webinstall.dev/golang
Go makes it easy to build simple, reliable, and efficient software.
---
Alias for https://webinstall.dev/golang
To update or switch versions, run `webi go@stable` (or `@v1.21`, `@beta`, etc).
### Files
```text
~/.config/envman/PATH.env
~/.local/opt/go/
~/go/
```
## Cheat Sheet
> Go is designed, through and through, to make Software Engineering easy. It's
> fast, efficient, reliable, and something you can learn in a weekend.
>
> If you subscribe to
> [_The Zen of Python_](https://www.python.org/dev/peps/pep-0020/), you'll
> [love](https://go-proverbs.github.io/) >
> [Go](https://www.youtube.com/watch?v=PAAkCSZUG1c).
You may also want to install the Go IDE tooling:
[go-essentials](/go-essentials).
### Hello World
1. Make and enter your project directory
```sh
mkdir -p ./hello/cmd/hello
pushd ./hello/
```
2. Initialize your `go.mod` to your _git repository_ url:
```sh
go mod init github.com/example/hello
```
3. Create a `hello.go`
```sh
cat << EOF >> ./cmd/hello/hello.go
package main
import (
"fmt"
)
func main () {
fmt.Println("Hello, World!")
}
EOF
```
4. Format, build, and run your `./hello`
```sh
go fmt ./...
go build -o hello ./cmd/hello/
./hello
```
You should see your output:
```text
> Hello, World!
```
### How to run a Go program as a service
On Linux:
```sh
# Install serviceman (compatible with systemd)
webi serviceman
```
```sh
# go into your programs 'opt' directory
pushd ./hello/
# swap 'hello' and './hello' for the name of your project and binary
sudo env PATH="$PATH" \
serviceman add --system --username "$(whoami)" --name hello -- \
./hello
# Restart the logging service
sudo systemctl restart systemd-journald
```

View File

@@ -1,5 +1,63 @@
#!/bin/pwsh
#!/usr/bin/env pwsh
echo "'go@$Env:WEBI_TAG' is an alias for 'golang@$Env:WEBI_VERSION'"
IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" }
curl.exe -fsSL "$Env:WEBI_HOST/golang@$Env:WEBI_VERSION" | powershell
$pkg_cmd_name = "go"
New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | out-null
$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"
$pkg_src = "$Env:USERPROFILE\.local\opt\$pkg_cmd_name-v$Env:WEBI_VERSION"
$pkg_dst = "$Env:USERPROFILE\.local\opt\$pkg_cmd_name"
$pkg_dst_cmd = "$pkg_dst\bin\$pkg_cmd_name"
$pkg_dst_bin = "$pkg_dst\bin"
if (!(Get-Command "git.exe" -ErrorAction SilentlyContinue))
{
& "$Env:USERPROFILE\.local\bin\webi-pwsh.ps1" git
# because we need git.exe to be available to golang immediately
$Env:PATH = "$Env:USERPROFILE\.local\opt\git\cmd;$Env:PATH"
}
# Fetch archive
IF (!(Test-Path -Path "$pkg_download"))
{
echo "Downloading $Env:PKG_NAME from $Env:WEBI_PKG_URL to $pkg_download"
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
& move "$pkg_download.part" "$pkg_download"
}
IF (!(Test-Path -Path "$pkg_src"))
{
echo "Installing $pkg_cmd_name"
# TODO: temp directory
# Enter opt
pushd .local\tmp
# Remove any leftover tmp cruft
Remove-Item -Path "$pkg_cmd_name*" -Recurse -ErrorAction Ignore
# Unpack archive
# Windows BSD-tar handles zip. Imagine that.
echo "Unpacking $pkg_download"
& tar xf "$pkg_download"
# Settle unpacked archive into place
echo "New Name: $pkg_cmd_name-v$Env:WEBI_VERSION"
Get-ChildItem "$pkg_cmd_name*" | Select -f 1 | Rename-Item -NewName "$pkg_cmd_name-v$Env:WEBI_VERSION"
echo "New Location: $pkg_src"
Move-Item -Path "$pkg_cmd_name-v$Env:WEBI_VERSION" -Destination "$Env:USERPROFILE\.local\opt"
# Exit tmp
popd
}
echo "Copying into '$pkg_dst' from '$pkg_src'"
Remove-Item -Path "$pkg_dst" -Recurse -ErrorAction Ignore
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
IF (!(Test-Path -Path go\bin)) { New-Item -Path go\bin -ItemType Directory -Force | out-null }
# Add to path
webi_path_add ~/.local/opt/go/bin
# Special to go: add default GOBIN to PATH
webi_path_add ~/go/bin

View File

@@ -2,10 +2,61 @@
set -e
set -u
__redirect_alias_golang() {
echo "'go@${WEBI_TAG:-stable}' is an alias for 'golang@${WEBI_VERSION-}'"
WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
curl -fsSL "$WEBI_HOST/golang@${WEBI_VERSION-}" | sh
GOBIN="${HOME}/go"
GOBIN_REAL="${HOME}/.local/opt/go-bin-v${WEBI_VERSION}"
# The package is 'golang', but the command is 'go'
pkg_cmd_name="go"
# NOTE: pkg_* variables can be defined here
# pkg_cmd_name
# pkg_src, pkg_src_bin, pkg_src_cmd
# pkg_dst, pkg_dst_bin, pkg_dst_cmd
#
# Their defaults are defined in _webi/template.sh at https://github.com/webinstall/packages
pkg_get_current_version() {
# 'go version' has output in this format:
# go version go1.14.2 darwin/amd64
# This trims it down to just the version number:
# 1.14.2
go version 2> /dev/null |
head -n 1 |
cut -d' ' -f3 |
sed 's:go::'
}
__redirect_alias_golang
pkg_format_cmd_version() {
# 'go v1.14.0' will be 'go1.14'
my_version=$(echo "$1" | sed 's:\.0::g')
echo "${pkg_cmd_name}${my_version}"
}
pkg_link() {
# 'pkg_dst' will default to $HOME/.local/opt/go
# 'pkg_src' will be the installed version, such as to $HOME/.local/opt/go-v1.14.2
rm -rf "$pkg_dst"
ln -s "$pkg_src" "$pkg_dst"
# Go has a special $GOBIN
# 'GOBIN' is set above to "${HOME}/go"
# 'GOBIN_REAL' will be "${HOME}/.local/opt/go-bin-v${WEBI_VERSION}"
rm -rf "$GOBIN"
mkdir -p "$GOBIN_REAL/bin"
ln -s "$GOBIN_REAL" "$GOBIN"
}
pkg_post_install() {
pkg_link
# web_path_add is defined in _webi/template.sh at https://github.com/webinstall/packages
# Updates PATH with
# "$HOME/.local/opt/go"
webi_path_add "$pkg_dst_bin"
webi_path_add "$GOBIN/bin"
}
pkg_done_message() {
echo "Installed 'go v$WEBI_VERSION' to ~/.local/opt/go"
}

View File

@@ -0,0 +1,11 @@
---
title: Golang Essentials (go-essentials alias)
homepage: https://webinstall.dev/go-essentials
tagline: |
Alias for https://webinstall.dev/go-essentials
alias: go-essentials
description: |
See https://webinstall.dev/go-essentials
---
Alias for https://webinstall.dev/go-essentials

View File

@@ -0,0 +1,5 @@
#!/bin/pwsh
echo "'go@$Env:WEBI_TAG' is an alias for 'golang@$Env:WEBI_VERSION'"
IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" }
curl.exe -fsSL "$Env:WEBI_HOST/golang@$Env:WEBI_VERSION" | powershell

View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -e
set -u
__redirect_alias_golang() {
echo "'go@${WEBI_TAG:-stable}' is an alias for 'golang@${WEBI_VERSION-}'"
WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
curl -fsSL "$WEBI_HOST/golang@${WEBI_VERSION-}" | sh
}
__redirect_alias_golang

View File

@@ -3,9 +3,14 @@ title: Go
homepage: https://golang.org
tagline: |
Go makes it easy to build simple, reliable, and efficient software.
alias: go
description: |
See https://webinstall.dev/go
---
To update or switch versions, run `webi golang@stable` (or `@v1.19`, `@beta`,
Alias for <https://webinstall.dev/go>.
To update or switch versions, run `webi go@stable` (or `@v1.21`, `@beta`,
etc).
### Files

View File

@@ -17,15 +17,6 @@ if (!(Get-Command "git.exe" -ErrorAction SilentlyContinue))
$Env:PATH = "$Env:USERPROFILE\.local\opt\git\cmd;$Env:PATH"
}
Write-Host '' -ForegroundColor red -BackgroundColor white
Write-Host '*********************' -ForegroundColor red -BackgroundColor white
Write-Host '* BREAKING CHANGE *' -ForegroundColor red -BackgroundColor white
Write-Host '*********************' -ForegroundColor red -BackgroundColor white
Write-Host '' -ForegroundColor red -BackgroundColor white
Write-Host ' ''webi golang'' will NOT install go tooling starting with go1.21+' -ForegroundColor red -BackgroundColor white
Write-Host ' use ''webi go-essentials'' to preserve the previous behavior' -ForegroundColor red -BackgroundColor white
Write-Host '' -ForegroundColor red -BackgroundColor white
# Fetch archive
IF (!(Test-Path -Path "$pkg_download"))
{
@@ -65,25 +56,6 @@ Remove-Item -Path "$pkg_dst" -Recurse -ErrorAction Ignore
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
IF (!(Test-Path -Path go\bin)) { New-Item -Path go\bin -ItemType Directory -Force | out-null }
# Special to go: re-run all go tooling builds
echo "Building go language tools..."
echo gopls
& "$pkg_dst_cmd" install golang.org/x/tools/gopls
echo golint
& "$pkg_dst_cmd" install golang.org/x/lint/golint
echo errcheck
& "$pkg_dst_cmd" install github.com/kisielk/errcheck
echo gotags
& "$pkg_dst_cmd" install github.com/jstemmer/gotags
echo goimports
& "$pkg_dst_cmd" install golang.org/x/tools/cmd/goimports
echo gorename
& "$pkg_dst_cmd" install golang.org/x/tools/cmd/gorename
echo gotype
& "$pkg_dst_cmd" install golang.org/x/tools/cmd/gotype
echo stringer
& "$pkg_dst_cmd" install golang.org/x/tools/cmd/stringer
# Add to path
webi_path_add ~/.local/opt/go/bin

View File

@@ -15,19 +15,6 @@ pkg_cmd_name="go"
#
# Their defaults are defined in _webi/template.sh at https://github.com/webinstall/packages
if [ -z "${WEBI__GO_ESSENTIALS-}" ]; then
# TODO nix for go1.21+
echo >&2 ""
printf >&2 '\e[31m%s:\e[0m\n' '#####################'
printf >&2 '\e[31m%s:\e[0m\n' '# BREAKING CHANGE #'
printf >&2 '\e[31m%s:\e[0m\n' '#####################'
echo >&2 ""
printf >&2 "\e[31m 'webi golang' will NOT install go tooling starting with go1.21+\e[0m\n"
printf >&2 "\e[31m use 'webi go-essentials' to preserve the previous behavior\e[0m\n"
echo >&2 ""
sleep 4
fi
pkg_get_current_version() {
# 'go version' has output in this format:
# go version go1.14.2 darwin/amd64
@@ -68,18 +55,8 @@ pkg_post_install() {
# "$HOME/.local/opt/go"
webi_path_add "$pkg_dst_bin"
webi_path_add "$GOBIN/bin"
if [ -z "${WEBI__GO_ESSENTIALS-}" ]; then
# TODO nix for go1.21+
WEBI__GO_INSTALL='true'
export WEBI__GO_INSTALL
"$HOME/.local/bin/webi" "go-essentials@${WEBI_TAG}"
fi
}
pkg_done_message() {
echo "Installed 'go v$WEBI_VERSION' to ~/.local/opt/go"
# note: literal $HOME on purpose
#shellcheck disable=SC2016
echo 'Installed go "x" tools to GOBIN=$HOME/go/bin'
}