easyfs

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2021 License: MIT Imports: 10 Imported by: 0

README

EasyFS

Simple static file server one can use to transfer files from one computer to another.

Website

Use Cases

CLI

The easyfs CLI takes a variable number of files and directories to serve and then:

  • serves them as a JSON API over HTTP,
  • serves a static website that consumes this API.
Library

server.go, file.go and router.go provide a simple JSON API to serve metadata about files as well as serving these files so they can be downloaded.

Build from source

To build this repository, you need Go 1.16+ as well as Node.js.

Then follow these steps:

  1. Clone this repository.
  2. Inside web/ run npm install.
  3. Depending on your OS run one of the following commands:
    • make linux-amd64
    • make darwin-amd64
    • make windows-amd64
  4. The built program can be found in the repositories root directory, and is called easyfs, or easyfs.exe on windows.

But why?

Initially I wanted to copy files from one computer to one that has no devtools whatsoever. So it started with:

package main

import "net/http"

func main() {
	http.Handle("/", http.FileServer(http.Dir("<my_dir>")))
	http.ListenAndServe(":8080", nil)
}

That worked and was basically all I needed; and then I added some more things.

License

This project is licensed under the MIT License.

Documentation

Overview

Package easyfs provides a JSON API that serves defined files of the host system over HTTP.

Index

Constants

This section is empty.

Variables

View Source
var Writer = log.Writer()

Writer is the output destination for this packages logger.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	AbsPath    string `json:"absPath"`
	Basename   string `json:"basename"`
	Size       uint64 `json:"size"`
	SizePretty string `json:"sizePretty"` // Size in a format like 10 MB or 12.5 KB and so on.
}

FileInfo describes a file that will be served over the API.

func FindFiles

func FindFiles(paths []string, includeDots bool) ([]FileInfo, error)

FindFiles searches all given paths recursively and returns all found files. paths can include relative paths, absolute paths as well as paths to files and directories. If includeDots is true then all hidden files and directories will be captured as well.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an HTTP Server.

func NewServer

func NewServer(mux *http.ServeMux, files []FileInfo, logOutput io.Writer) *Server

NewServer returns an a new Server that serves the given files over HTTP.

logOutput defines where internal logs will be written; to disable logging one can pass io.Discard.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL