-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[noodle] Init local fs wraps http.Dir
- using `os.Open` would work as well but it would have many 500 if user has url like `index.html/is-not-a-folder` - it is fixed in golang/go#18984 there is a function called `mapDirOpenError` - [ ] TODO: serveFile would call `dirList` and it can't be disabled ...
- Loading branch information
Showing
13 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<html> | ||
<head> | ||
<title>I am title</title> | ||
<link rel="stylesheet" href="main.css"> | ||
</head> | ||
<body> | ||
<p>If you being just staring at the sun light</p> | ||
<table> | ||
<tr> | ||
<td>a</td> | ||
<td>b</td> | ||
</tr> | ||
<tr> | ||
<td>c</td> | ||
<td>d</td> | ||
</tr> | ||
</table> | ||
<p>echarts example | ||
<a target="_blank" | ||
href="https://ecomfe.github.io/echarts-doc/public/en/tutorial.html#Get%20Started%20with%20ECharts%20in%205%20minutes">get | ||
started</a> | ||
</p> | ||
<div id="main" style="width: 600px;height:400px;"></div> | ||
<p>image from unsplash</p> | ||
<img src="https://source.unsplash.com/random" alt="unsplash random"> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.2/echarts-en.common.min.js"></script> | ||
<script src="main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body { | ||
background-color: lightcyan; | ||
margin: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
// alert('this is main'); | ||
|
||
console.log({'o': 'bject'}); | ||
|
||
var myChart = echarts.init(document.getElementById('main')); | ||
|
||
// 指定图表的配置项和数据 | ||
var option = { | ||
title: { | ||
text: 'ECharts 入门示例' | ||
}, | ||
tooltip: {}, | ||
legend: { | ||
data:['销量'] | ||
}, | ||
xAxis: { | ||
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"] | ||
}, | ||
yAxis: {}, | ||
series: [{ | ||
name: '销量', | ||
type: 'bar', | ||
data: [5, 20, 36, 10, 10, 20] | ||
}] | ||
}; | ||
|
||
// 使用刚指定的配置项和数据显示图表。 | ||
myChart.setOption(option); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"fmt" | ||
"os" | ||
"github.com/dyweb/gommon/noodle" | ||
) | ||
|
||
func main() { | ||
fs := "default" | ||
if len(os.Args) > 1 { | ||
fs = os.Args[1] | ||
} | ||
fmt.Println(fs) | ||
addr := ":8080" | ||
//addr := ":6667" # https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers 6665-6669 is for IRC ... | ||
fmt.Printf("listen on %s\n", addr) | ||
var root http.FileSystem | ||
switch fs { | ||
case "default": | ||
root = http.Dir("./assets") | ||
case "local": | ||
root = noodle.NewLocal("./assets") | ||
default: | ||
panic("unknown fs") | ||
} | ||
http.ListenAndServe(addr, http.FileServer(root)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Noodle | ||
|
||
## TODO | ||
|
||
- generate go file based on assets (like most bind-data ish library does) | ||
- figure out how to create and append zipfile, without relying on external zip binary | ||
|
||
## Ref | ||
|
||
- https://github.com/GeertJohan/go.rice 1.6k star, used to use it for Ayi | ||
- https://github.com/shurcooL/vfsgen 236 star listed most packages in alternative section | ||
- https://github.com/shurcooL/vfsgen#alternatives | ||
- https://www.ueber.net/who/mjl/blog/p/assets-in-go-binaries/ describes how to append zip | ||
- https://github.com/cookieo9/resources-go pretty like go.rice | ||
- [golang-nuts/including html contents of a file at compile time](https://groups.google.com/forum/#!topic/golang-nuts/9QUjmDED96E) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package noodle | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
var _ http.FileSystem = (*LocalFs)(nil) | ||
|
||
type LocalFs struct { | ||
root string | ||
dir http.Dir | ||
} | ||
|
||
func NewLocal(root string) *LocalFs { | ||
return &LocalFs{root: root, dir: http.Dir(root)} | ||
} | ||
|
||
func (fs *LocalFs) Open(name string) (http.File, error) { | ||
//return os.Open(filepath.Join(fs.root, name)) | ||
// NOTE: http.Dir has extra error handling, https://github.com/golang/go/issues/18984 | ||
// some operation are mapped to 404 instead of 500 | ||
// TODO: but it supports list dir and can't be disabled ... | ||
return fs.dir.Open(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package noodle | ||
|
||
// A file system that fall back to another if file not found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package noodle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package noodle | ||
|
||
// generate assets file with flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package noodle | ||
|
||
import "github.com/dyweb/gommon/util/logutil" | ||
|
||
var log = logutil.NewPackageLogger() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package noodle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters