Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aran committed Sep 2, 2024
0 parents commit 98e2446
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OSX leaves these everywhere on SMB shares
._*

# OSX trash
.DS_Store

# From https://github.com/bazelbuild/bazel/blob/master/.gitignore

/bazel-*
# Ignore outputs generated during Bazel bootstrapping.
/output/
20 changes: 20 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load("@rules_go//go:def.bzl", "TOOLS_NOGO", "nogo")

nogo(
name = "nogo",
visibility = ["//visibility:public"],
deps = TOOLS_NOGO,
)

go_library(
name = "rand32_lib",
srcs = ["rand32.go"],
visibility = ["//visibility:private"],
)

go_binary(
name = "rand32",
embed = [":rand32_lib"],
visibility = ["//visibility:public"],
)
12 changes: 12 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bazel_dep(name = "gazelle", version = "0.38.0")
bazel_dep(name = "rules_go", version = "0.50.0")

####
# rules_go
####
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")
go_sdk.nogo(nogo = "//:nogo")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
131 changes: 131 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/aran

go 1.23.0
Empty file added go.sum
Empty file.
27 changes: 27 additions & 0 deletions rand32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"crypto/rand"
"encoding/base64"
"fmt"
"os"
)

func main() {
c := 32 * 6 / 8
out := os.Stdout

encoded := base64.NewEncoder(base64.URLEncoding, out)
defer encoded.Close()
b := make([]byte, c)
_, err := rand.Read(b)
if err != nil {
fmt.Fprintln(os.Stderr, "rand error: ", err)
os.Exit(2)
}
_, err = encoded.Write(b)
if err != nil {
fmt.Fprintln(os.Stderr, "write error: ", err)
os.Exit(3)
}
}

0 comments on commit 98e2446

Please sign in to comment.