Skip to content

Commit

Permalink
uhhhh website
Browse files Browse the repository at this point in the history
  • Loading branch information
dezren39 committed Jan 30, 2024
1 parent 93579a2 commit 751a67a
Show file tree
Hide file tree
Showing 50 changed files with 6,409 additions and 168 deletions.
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21.3
go 1.21.5

use (
./sources/chat
Expand Down
273 changes: 270 additions & 3 deletions go.work.sum

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions sources/identity/auth/connection.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,106 @@
package auth

import (
"context"
"database/sql"
"encoding/json"
"fmt"
"os"
"sync"
"time"

"github.com/charmbracelet/log"
"github.com/nrednav/cuid2"
)

type contextKey struct {
name string
}

var ConnectionMapKey = &contextKey{"ConnectionMap"}

// WithConnectionMap adds the SafeConnectionMap to the context
func WithConnectionMap(ctx context.Context, connections *SafeConnectionMap) context.Context {
return context.WithValue(ctx, ConnectionMapKey, connections)
}

// GetConnectionMap retrieves the SafeConnectionMap from the context
func GetConnectionMap(ctx context.Context) (*SafeConnectionMap, bool) {
connections, ok := ctx.Value(ConnectionMapKey).(*SafeConnectionMap)
return connections, ok
}

type SafeConnectionMap struct {
mu sync.RWMutex
data map[string]Connection
}

// NewSafeConnectionMap creates and returns a new SafeConnectionMap
func NewSafeConnectionMap() *SafeConnectionMap {
return &SafeConnectionMap{
data: make(map[string]Connection),
}
}

// Get safely retrieves an element from the map
func (sm *SafeConnectionMap) Get(key string) (Connection, bool) {
sm.mu.RLock()
defer sm.mu.RUnlock()
val, ok := sm.data[key]
return val, ok
}

// Set safely adds an element to the map
func (sm *SafeConnectionMap) Set(key string, value Connection) {
sm.mu.Lock()
defer sm.mu.Unlock()
sm.data[key] = value
}

// Delete safely removes an element from the map
func (sm *SafeConnectionMap) Delete(key string) {
sm.mu.Lock()
defer sm.mu.Unlock()
delete(sm.data, key)
}

// All safely retrieves all elements from the map
func (sm *SafeConnectionMap) All() map[string]Connection {
sm.mu.RLock()
defer sm.mu.RUnlock()
return sm.data
}

// Keys safely retrieves all keys from the map
func (sm *SafeConnectionMap) Keys() []string {
sm.mu.RLock()
defer sm.mu.RUnlock()
keys := make([]string, 0, len(sm.data))
for k := range sm.data {
keys = append(keys, k)
}
return keys
}

// Len safely retrieves the length of the map
func (sm *SafeConnectionMap) Len() int {
sm.mu.RLock()
defer sm.mu.RUnlock()
return len(sm.data)
}

// Values safely retrieves all values from the map
func (sm *SafeConnectionMap) Values() []Connection {
sm.mu.RLock()
defer sm.mu.RUnlock()
values := make([]Connection, 0, len(sm.data))
for _, v := range sm.data {
values = append(values, v)
}
return values
}

// Connection represents a connection
type Connection struct {
ConnectionID *string
Status *string
Expand Down Expand Up @@ -347,6 +437,23 @@ func (b *Connection) Update(column string, value interface{}) error {

}

func (b *Connection) JSON() (string, error) {
jsonB, err := json.Marshal(b)
if err != nil {
return "", fmt.Errorf("failed to marshal connection: %v", err)
}
return string(jsonB), nil
}

func (b *Connection) HTML() (string, error) {
jsonString, err := b.JSON()
if err != nil {
return "", fmt.Errorf("failed to marshal connection: %v", err)
}
return "<pre style=\"white-space: pre-wrap; overflow-wrap: anywhere;\">" + jsonString + "</pre>", nil

}

func (b *Connection) Insert() (*string, error) {
if b.ConnectionID != nil {
return nil, fmt.Errorf("inserting connection with existing connection id")
Expand Down
14 changes: 0 additions & 14 deletions sources/identity/auth/observability.go

This file was deleted.

3 changes: 3 additions & 0 deletions sources/identity/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env pwsh

templ generate ; go build . ; .\identity.exe serve
55 changes: 37 additions & 18 deletions sources/identity/go.mod
Original file line number Diff line number Diff line change
@@ -1,55 +1,74 @@
module github.com/developing-today/code/src/identity

go 1.21.3
go 1.21.5

toolchain go1.21.5

require (
github.com/a-h/templ v0.2.543
github.com/angelofallars/htmx-go v0.4.1
github.com/charmbracelet/bubbles v0.17.1
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.1
github.com/charmbracelet/ssh v0.0.0-20240104172912-e11ae277b249
github.com/charmbracelet/melt v0.6.0
github.com/charmbracelet/promwish v0.7.1-0.20240111010057-b31c9c27b2d7
github.com/charmbracelet/ssh v0.0.0-20240129235603-6bd0d80adf41
github.com/charmbracelet/wish v1.2.1-0.20240105172733-3e6f92a16611
github.com/go-chi/chi/v5 v5.0.11
github.com/gowebly/helpers v0.3.0
github.com/knadh/koanf v1.5.1-0.20230129133018-38c5fe1d9b40
github.com/knadh/koanf/parsers/kdl v0.1.0
github.com/muesli/reflow v0.3.0
github.com/nrednav/cuid2 v1.0.0
github.com/sblinch/kdl-go v0.0.0-20240108033718-e453df3dbf65
github.com/spf13/cobra v1.8.0
github.com/tursodatabase/libsql-client-go v0.0.0-20231216154754-8383a53d618f
golang.org/x/crypto v0.17.0
golang.org/x/crypto v0.18.0
)

replace github.com/charmbracelet/promwish => github.com/dezren39/promwish v0.7.1-0.20240130030052-ce34dc0a7c31

require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/keygen v0.5.0 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/charmbracelet/melt v0.6.0 // indirect
github.com/charmbracelet/promwish v0.7.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240129143450-0ee713645824 // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240129143450-0ee713645824 // indirect
github.com/containerd/console v1.0.4-0.20230706203907-8f6c4e4faef5 // indirect
github.com/creack/pty v1.1.21 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/knadh/koanf v1.5.1-0.20230129133018-38c5fe1d9b40 // indirect
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.6 // indirect
github.com/sblinch/kdl-go v0.0.0-20240108033718-e453df3dbf65 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
github.com/u-root/u-root v0.12.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
nhooyr.io/websocket v1.8.10 // indirect
)
Loading

0 comments on commit 751a67a

Please sign in to comment.