From 7b21727285e50b0b050c4ddd70d07542229c5366 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:17:03 -0700 Subject: init --- go/file_server.go | 11 +++++++++ go/gofs.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ go/hello_world.go | 5 ++++ go/owm.go | 14 +++++++++++ 4 files changed, 101 insertions(+) create mode 100644 go/file_server.go create mode 100644 go/gofs.go create mode 100644 go/hello_world.go create mode 100644 go/owm.go (limited to 'go') diff --git a/go/file_server.go b/go/file_server.go new file mode 100644 index 0000000..eb70101 --- /dev/null +++ b/go/file_server.go @@ -0,0 +1,11 @@ +package main + +import ( + "log" + "net/http" +) + +func main() { + // Simple static webserver: + log.Fatal(http.ListenAndServe("0.0.0.0:8080", http.FileServer(http.Dir("/home/nik")))) +} diff --git a/go/gofs.go b/go/gofs.go new file mode 100644 index 0000000..4b47c81 --- /dev/null +++ b/go/gofs.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + "io/fs" + "log" + "net/url" + "os" + "path/filepath" + + "github.com/pkg/sftp" +) + +func main() { + // Parse the command-line arguments + if len(os.Args) < 2 { + log.Fatalf("Usage: %v [user@domain.com:/directory/i/want/to/mount]", os.Args[0]) + } + remoteAddr := os.Args[1] + + // Connect to the remote server using SFTP + sshConfig := &ssh.ClientConfig{ + User: "username", + Auth: []ssh.AuthMethod{ + ssh.Password("password"), + }, + } + conn, err := ssh.Dial("tcp", remoteAddr, sshConfig) + if err != nil { + log.Fatalf("Failed to connect to remote server: %v", err) + } + client, err := sftp.NewClient(conn) + if err != nil { + log.Fatalf("Failed to create SFTP client: %v", err) + } + + // List the contents of the remote directory + entries, err := client.ReadDir("/path/to/remote/directory") + if err != nil { + log.Fatalf("Failed to list remote directory: %v", err) + } + + // Create a local filesystem for the remote directory + fs := os.DirFS("/path/to/local/directory") + + // Add each file from the remote directory to the local filesystem + for _, entry := range entries { + filename := filepath.Join(fs, entry.Name()) + if err = fs.MkdirAll(filepath.Dir(filename), 0755); err != nil { + log.Fatalf("Failed to create directory: %v", err) + } + if _, err := client.OpenFile(entry.Name(), os.O_RDONLY, fs); err != nil { + log.Fatalf("Failed to open remote file: %v", err) + } + } + + // Mount the local filesystem as a directory in the client's namespace + if err = os.MkdirAll("/path/to/mounted/directory", 0755); err != nil { + log.Fatalf("Failed to create mount point: %v", err) + } + if err := syscall.Mount(fs, "/path/to/mounted/directory", "", syscall.MS_RDONLY, ""); err != nil { + log.Fatalf("Failed to mount filesystem: %v", err) + } + + // List the contents of the local directory to verify that it has been mounted correctly + entries, err = os.ReadDir("/path/to/mounted/directory") + if err != nil { + log.Fatalf("Failed to list mounted directory: %v", err) + } + fmt.Println(entries) +} diff --git a/go/hello_world.go b/go/hello_world.go new file mode 100644 index 0000000..9fd8348 --- /dev/null +++ b/go/hello_world.go @@ -0,0 +1,5 @@ +package main + +func main() { + println("hello world!") +} diff --git a/go/owm.go b/go/owm.go new file mode 100644 index 0000000..31d18c5 --- /dev/null +++ b/go/owm.go @@ -0,0 +1,14 @@ +package main + +import ( + "net/http" +) + +func main() { + //weather, err := http.Get("https://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&appid=" + apikey) + weather, err := http.Get("https://api.openweathermap.org/data/2.5/weather?lat=47.772&lon=-122.22&appid=0c7757e1fecf8d20a8a385b2be959d98") + if err != nil { + print(err) + } + print(weather) +} -- cgit v1.2.3