init
This commit is contained in:
11
go/file_server.go
Normal file
11
go/file_server.go
Normal file
@ -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"))))
|
||||
}
|
||||
71
go/gofs.go
Normal file
71
go/gofs.go
Normal file
@ -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)
|
||||
}
|
||||
5
go/hello_world.go
Normal file
5
go/hello_world.go
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
println("hello world!")
|
||||
}
|
||||
14
go/owm.go
Normal file
14
go/owm.go
Normal file
@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user