serve files

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

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

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

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

Loading…
Cancel
Save