Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.FS interface types wrapper #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AndreRenaud
Copy link

I wrote this as a side effect of a separate command line tool I was working on, and it felt like it might be more widely useful.

See https://pkg.go.dev/io/fs for interface details

Example usage:

package main

import (
	"log"
	"net/http"
	"os"

	"github.com/t3rm1n4l/go-mega"
)

var USER string = os.Getenv("MEGA_USER")
var PASSWORD string = os.Getenv("MEGA_PASSWD")

func main() {
	m := mega.New()
	if err := m.Login(USER, PASSWORD); err != nil {
		log.Fatalf("Cannot connect to Mega: %s", err)
	}

	mux := http.NewServeMux()
	mux.Handle("/", http.FileServer(http.FS(m)))

	if err := http.ListenAndServe(":8000", mux); err != nil {
		log.Fatal(err)
	}
}

Then browse to http://localhost:8000 to see the content.

There aren't any tests yet (which there should be), but I thought I'd ask for feedback before cleaning everything up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant