commit 36065e83e4be44aa8e9fbcd1997655383b85f986 Author: sandyx Date: Tue Nov 19 11:05:22 2024 -0600 first commit diff --git a/example.html b/example.html new file mode 100644 index 0000000..73680f2 --- /dev/null +++ b/example.html @@ -0,0 +1,80 @@ +
+68000.pdf
+Addison.Wesley.OpenGL.Programming.Guide.8th.Edition.Mar.2013.ISBN.0321773039.pdf
+GenesisSoftwareManual.pdf
+Hoare78.pdf
+No.Starch.Absolute.FreeBSD.The.Complete.Guide.To.FreeBSD.2nd.Edition.Nov.2007.ISBN.1593271514.pdf
+Objective-C For Dummies
+Objective-C Programming The Big Nerd Ranch Guide 2011.pdf
+Programming in Objective-C - 6th Edition.pdf
+The Book of Ruby - A Hands-On Guide for the Adventurous.pdf
+The GNU Make Book.pdf
+Virtual Memory.html
+adevelopersguidetonetinazure.pdf
+airevolutioninmedicine_V2.pdf
+airevolutioninnetworkingsecurityandemergingtechnologies.pdf
+airevolutioninprojectmanagement.pdf
+artificialintelligenceforbusiness2ndedition.pdf
+autotools-2nd-edition-a-practitioners-guide-to-gnu-autoconf-automake-and-libtool-2nd-edition-9781593279721-1593279728.pdf
+beginning-x64-assembly-programming-from-novice-to-avx-professional-9781484250754-9781484250761-1484250753-1484250761.pdf
+beyondthealgorithm_aisecurityprivacyandethics.pdf
+binsok.pdf
+buildingmoderncliapplicationsingo.pdf
+c10andnet6_moderncross-platformdevelopment.pdf
+c12andnet8_moderncross-platformdevelopmentfundamentals.pdf
+cdatastructuresandalgorithms_secondedition.pdf
+cinterviewguide.pdf
+cleancodewithcsharp.pdf
+cworkshop.pdf
+deeplearningillustrated.pdf
+domain-drivendesignwithgolang.pdf
+effectiveconcurrencyingo.pdf
+enterpriseapplicationdevelopmentwithc10andnet6.pdf
+event-drivenarchitectureingolang.pdf
+foundationalpythonfordatascience.pdf
+foundations-of-game-engine-development-volume-1-mathematics-1nbsped-0985811749-9780985811747_compress.pdf
+foundations-of-game-engine-development-volume-2-rendering-2-4nbsped-9780985811754_compress.pdf
+foundationsofdeepreinforcementlearning.pdf
+functionalprogrammingingo.pdf
+futex.pdf
+goprogramming_frombeginnertoprofessional.pdf
+goprogrammingcookbook.pdf
+grpcgoforprofessionals.pdf
+hands-onnetworkprogrammingwithcandnetcore.pdf
+hands-onobject-orientedprogrammingwithc.pdf
+hands-onsoftwarearchitecturewithgolang.pdf
+hands-onsoftwareengineeringwithgolang.pdf
+hands-onsystemprogrammingwithgo.pdf
+high-performanceprogrammingincandnet.pdf
+implementingevent-drivenmicroservicesarchitectureinnet7.pdf
+introducingmachinelearning.pdf
+learndatastructuresandalgorithmswithgolang.pdf
+learningdeeplearning.pdf
+machinelearninginproduction.pdf
+machinelearningwithpythonforeveryone.pdf
+masteringgo.pdf
+meltdown.pdf
+microservicescommunicationinnetusinggrpc.pdf
+microservicesdesignpatternsinnet.pdf
+microserviceswithgo.pdf
+mvvmpatterninnetmaui.pdf
+netmauicross-platformapplicationdevelopment.pdf
+netmauiforcdevelopers.pdf
+parallelprogrammingandconcurrencywithc10andnet6.pdf
+pm.pdf
+pragmaticai.pdf
+pragmatictest-drivendevelopmentincandnet.pdf
+predictiveanalytics_dataminingmachinelearninganddatascienceforpractitioners.pdf
+programmingmlnet.pdf
+quickstartguidetolargelanguagemodels.pdf
+real-worldimplementationofcdesignpatterns.pdf
+refactoringwithc.pdf
+responsibleai.pdf
+simd-software-rendering.pdf
+simd.pdf
+softwarearchitecturewithc10andnet6_thirdedition.pdf
+spectre.pdf
+test-drivendevelopmentingo.pdf
+vbNet_programming.pdf
+xlib.pdf
+
diff --git a/file name with spaces b/file name with spaces new file mode 100644 index 0000000..434de0e --- /dev/null +++ b/file name with spaces @@ -0,0 +1 @@ +it has some text in it \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fae181e --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module dragon.ooo + +go 1.21.4 diff --git a/main.go b/main.go new file mode 100644 index 0000000..ac15dd2 --- /dev/null +++ b/main.go @@ -0,0 +1,126 @@ +package main + +import ( + "flag" + "fmt" + "io" + "log" + "net/http" + "net/url" + "os" +) + +//easily put attrs in a tag +type htmlAttrs map[string]string +func (attrs htmlAttrs) String() string { + var ret string + for k, v := range attrs { + ret += fmt.Sprintf("%s=\"%s\" ", k, url.QueryEscape(v)) + } + + return ret +} + +func wrapWithTagAttrs(str, tag string, a htmlAttrs) string { + return fmt.Sprintf("<%s %s>%s", tag, a.String(), str, tag) +} + +func wrapWithTag(str string, tag string) string { + return fmt.Sprintf("<%s>%s", tag, str, tag) +} + +//cleaner than making an attr for one href +func wrapWithTagHref(str string, tag string) string { + taggedString := fmt.Sprintf("<%s href=%s>%s", tag, url.QueryEscape(str), str, tag) +} + +func serveStylesheet(w http.ResponseWriter, r *http.Request) { + sheet, err := os.Open("style.css") + if err != nil { + http.Error(w, "File not found", http.StatusNotFound) + return + } + defer sheet.Close() + + w.Header().Set("Content-Disposition", "attachment; filename=style.css") + w.Header().Set("Content-Type", "text/css") + + _, err = io.Copy(w, sheet) + if err != nil { + http.Error(w, "Error sending file", http.StatusInternalServerError) + return + } + +} + +func main() { + port := flag.String("p", "6969", "port to serve on") + directory := flag.String("d", ".", "the directory of static file to host") + flag.Parse() + + var contents string + entries, err := os.ReadDir(*directory) + if err != nil { + log.Fatal(err) + } + + for _, e := range entries { + new := e.Name() + http.HandleFunc("/" + url.QueryEscape(new), func(w http.ResponseWriter, r *http.Request) { + log.Println("Request for resource: ", r.RequestURI) + + //could also generate the css at runtime + if r.RequestURI == "/style.css" { + serveStylesheet(w, r) + return + } + + file, err := os.Open(*directory + "/" + new) + if err != nil { + http.Error(w, "File not found.", http.StatusNotFound) + return + } + defer file.Close() + + w.Header().Set("Content-Disposition", "attachment; filename=" + new) + w.Header().Set("Content-Type", "application/octet-stream") + + _, err = io.Copy(w, file) + if err != nil { + http.Error(w, "Error sending file.", http.StatusInternalServerError) + return + } + }) + + gridAttrs := htmlAttrs { + "class": "grid-item", + } + + hrefAttrs := htmlAttrs { + "href": e.Name(), + } + + var href string + href = wrapWithTagAttrs(e.Name(), "a", hrefAttrs) + contents += wrapWithTagAttrs(href, "div", gridAttrs) + contents += "\n" + } + + gridContainerAttrs := htmlAttrs { + "class": "grid-container", + } + + contents = wrapWithTagAttrs(contents, "div", gridContainerAttrs) + contents = wrapWithTag(contents, "pre") + contents = wrapWithTag("", "head") + contents + contents = wrapWithTag(contents, "html") + contents = "" + contents + + handler := func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(contents)) + } + + http.Handle("/", http.HandlerFunc(handler)) + log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) + log.Fatal(http.ListenAndServe(":"+*port, nil)) +} diff --git a/stress.rb b/stress.rb new file mode 100644 index 0000000..2de7568 --- /dev/null +++ b/stress.rb @@ -0,0 +1,9 @@ +require 'net/http' + +url = URI.parse("") +req = Net::HTTP::Get.new(url.to_s) +res = Net::HTTP.start(url.host, url.port) { |http| + http.request(req) +} + +puts res.body \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..a7a2de2 --- /dev/null +++ b/style.css @@ -0,0 +1,11 @@ +.grid-container { + font-family: "Iosevka"; + font-size: 20px; + display: grid; + grid-template-columns: auto auto auto; +} + +.grid-item { + padding: 0px; + text-align: center; +}