Skip to content

Commit e3c9c83

Browse files
authored
Add example-shttp-fileserver (#156)
Add example for simple fileserver that lists/serves all files under the current working directory.
1 parent 9667862 commit e3c9c83

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build: scion-bat \
1717
scion-sensorfetcher scion-sensorserver \
1818
scion-ssh scion-sshd \
1919
example-helloworld \
20-
example-shttp-client example-shttp-server example-shttp-proxy
20+
example-shttp-client example-shttp-server example-shttp-fileserver example-shttp-proxy
2121

2222
clean:
2323
go clean ./...
@@ -98,6 +98,10 @@ example-shttp-client:
9898
example-shttp-server:
9999
go build -o $(BIN)/$@ ./_examples/shttp/server
100100

101+
.PHONY: example-shttp-fileserver
102+
example-shttp-fileserver:
103+
go build -o $(BIN)/$@ ./_examples/shttp/fileserver
104+
101105
.PHONY: example-shttp-proxy
102106
example-shttp-proxy:
103107
go build -o $(BIN)/$@ ./_examples/shttp/proxy

_examples/shttp/fileserver/main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020 ETH Zurich
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// example-shttp-fileserver is a simple HTTP fileserver that serves all files
16+
// and subdirectories under the current working directory.
17+
package main
18+
19+
import (
20+
"flag"
21+
"fmt"
22+
"log"
23+
"net/http"
24+
25+
"github.com/netsec-ethz/scion-apps/pkg/shttp"
26+
)
27+
28+
func main() {
29+
port := flag.Uint("p", 443, "port the server listens on")
30+
flag.Parse()
31+
32+
handler := http.FileServer(http.Dir(""))
33+
log.Fatal(shttp.ListenAndServe(fmt.Sprintf(":%d", *port), handler, nil))
34+
}

0 commit comments

Comments
 (0)