serve files

master v0.1.0
Jordan Orelli 7 years ago
parent 1f57a1aa5d
commit 8dee9e5b56

@ -11,7 +11,7 @@ import (
type server struct {
port int
root string
fs http.Handler
out chan events.BackgroundEvent
}
@ -29,15 +29,15 @@ func (s *server) listen() {
func (s *server) setRoot(path string) {
log.Printf("server setting root to %s\n", path)
s.root = path
s.fs = http.FileServer(http.Dir(path))
}
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if s.root == "" {
if s.fs == nil {
writeNotInitializedResponse(w)
return
}
fmt.Fprintf(w, "root: %s", s.root)
s.fs.ServeHTTP(w, r)
}
func writeNotInitializedResponse(w http.ResponseWriter) {

@ -18,12 +18,10 @@
@implementation MainViewController
- (void) loadView {
NSLog(@"[MainViewController] loadView");
self.view = [[MainView alloc] init];
}
- (void) viewDidLoad {
NSLog(@"[MainViewController] viewDidLoad");
[super viewDidLoad];
// set window dimensions
@ -65,6 +63,7 @@
[tableContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
[tableContainer setHasVerticalScroller:YES];
[tableContainer setFocusRingType:NSFocusRingTypeNone];
[tableContainer setBorderType:NSBezelBorder];
[self.view addSubview:tableContainer];
NSTableView *tableView = [[NSTableView alloc] init];
@ -126,7 +125,6 @@
}
- (void) selectDirectory {
NSLog(@"[MainViewController] select directory start");
[self.selectDirectoryPanel beginWithCompletionHandler:^(NSInteger result) {
if (result != NSFileHandlingPanelOKButton) {
NSLog(@"[MainViewController] user canceled select directory window");
@ -143,13 +141,11 @@
}
- (void) serverDidReceiveRequest:(RequestMeta *)meta {
NSLog(@"[MainViewController] request start: {%d %s}", meta->seq, meta->path);
[[self history] addRequestItem:meta];
[[self historyTable] reloadData];
}
- (void) serverDidWriteResponse:(ResponseMeta *)meta {
NSLog(@"[MainViewController] request finish: {%d %d %d}", meta->seq, meta->status, meta->bytes);
[[self history] addResponseItem:meta];
[[self historyTable] reloadData];
}

@ -20,7 +20,6 @@
}
- (id) tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger) row {
NSLog(@"[RequestHistory] objectValueForTableColumn: %@ row: %zd", column, row);
RequestHistoryItem *item = [[self items] objectAtIndex:row];
if (!item) {
return nil;
@ -42,12 +41,10 @@
}
- (void) addRequestItem:(RequestMeta *)meta {
NSLog(@"[RequestHistory] add request item");
[[self items] addObject:[RequestHistoryItem itemWithRequestMeta:meta]];
}
- (void) addResponseItem:(ResponseMeta *)meta {
NSLog(@"[RequestHistory] add response item");
id item = [[self items] objectAtIndex:meta->seq-1];
[item updateWithResponseMeta:meta];
}

Loading…
Cancel
Save