Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
# Better Go Playground

[![Docker Hub](https://img.shields.io/docker/pulls/x1unix/go-playground.svg)](https://hub.docker.com/r/x1unix/go-playground)
[![Docker Hub](https://img.shields.io/docker/v/x1unix/go-playground.svg?sort=date)](https://hub.docker.com/r/x1unix/go-playground)
[![Build Status](https://travis-ci.org/x1unix/go-playground.svg?branch=master)](https://travis-ci.org/x1unix/go-playground)
[![Coverage Status](https://coveralls.io/repos/github/x1unix/go-playground/badge.svg?branch=dev)](https://coveralls.io/github/x1unix/go-playground?branch=dev)
[![Goreportcard](https://goreportcard.com/badge/github.com/x1unix/go-playground)](https://goreportcard.com/report/github.com/x1unix/go-playground)

Improved Go Playground powered by Monaco Editor and React
Improved Go Playground powered by Monaco Editor and React - [https://goplay.tools/](https://goplay.tools)

![alt text](./docs/demo.gif)
![alt text](docs/demo.gif)

## Features

* 🌚 Dark theme
* 💡 Code autocomplete
* 💾 Load and save files
* 📔 Snippets and tutorials
* ⚙ Customization (fonts, ligatures, etc)
* 🛠 [WebAssembly](https://github.com/golang/go/wiki/WebAssembly) support
* 🌚 Dark theme


And more
And more !

## Installation

## Demo
### Docker

[https://goplay.tools/](https://goplay.tools)
Playground is available via [Docker Hub](https://hub.docker.com/r/x1unix/go-playground).

## Installation
See [wiki](https://github.com/x1unix/go-playground/wiki/Docker) for usage info.

### Local instance

Playground is available via [Docker Hub](https://hub.docker.com/r/x1unix/go-playground) or can be built and run locally (**Go 1.12+** and **Node.js** required):
Service can be built and run locally (**Go 1.12+** and **Node.js** required):

```
$ git clone https://github.com/x1unix/go-playground.git
Expand Down
Binary file modified docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion web/src/services/go/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ export type bytes = Array<number>;
export type NodeCallback<T> = (Error, T) => void;

export const encoder = new TextEncoder();
export const decoder = new TextDecoder('utf-8');
export const decoder = new TextDecoder('utf-8');


export class SyscallError extends Error {
constructor(public code: string, message: string) {
super(message);
}
}

export const enosys = () => {
return new SyscallError('ENOSYS', 'not implemented')
};
45 changes: 33 additions & 12 deletions web/src/services/go/fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeCallback } from './foundation';
import { NodeCallback, enosys } from './foundation';

export type FileDescriptor = number;

Expand All @@ -10,6 +10,29 @@ export interface IFileSystem {
write(fd: FileDescriptor, buf: Uint8Array, offset: number, length: number, position: number, callback: NodeCallback<number>)
open(path: string, flags, mode, callback)
fsync(fd, callback)
chmod(path, mode, callback)
chown(path, uid, gid, callback)
close(fd, callback)
fchmod(fd, mode, callback)
fchown(fd, uid, gid, callback)
fstat(fd, callback)
fsync(fd, callback)
ftruncate(fd, length, callback)
lchown(path, uid, gid, callback)
link(path, link, callback)
lstat(path, callback)
mkdir(path, perm, callback)
open(path, flags, mode, callback)
read(fd, buffer, offset, length, position, callback)
readdir(path, callback)
readlink(path, callback)
rename(from, to, callback)
rmdir(path, callback)
stat(path, callback)
symlink(path, link, callback)
truncate(path, length, callback)
unlink(path, callback)
utimes(path, atime, mtime, callback)
}

/**
Expand All @@ -21,7 +44,9 @@ export interface IWriter {
}

/**
* FileSystemWrapper is wrapper class for FS simulation
* FileSystemWrapper is file system stub implementation for browser
*
* Source: wasm_exec.js:39 in Go 1.14
*/
export class FileSystemWrapper {
descriptors = new Map<FileDescriptor, IWriter>();
Expand All @@ -42,32 +67,28 @@ export class FileSystemWrapper {
writeSync(fd: FileDescriptor, buf: Uint8Array) {
const writer = this.descriptors.get(fd);
if (!writer) {
const err = new Error('not implemented');
err['code'] = 'ENOENT';
throw err;
throw enosys();
}

return writer.write(buf);
}

write(fd: FileDescriptor, buf: Uint8Array, offset: number, length: number, position: number, callback: NodeCallback<number>) {
if (offset !== 0 || length !== buf.length || position !== null) {
throw new Error("not implemented");
callback(enosys(), null);
return;
}
const n = this.writeSync(fd, buf);
callback(null, n);
}

open(path: string, flags, mode, callback) {
const err = new Error("not implemented");
err['code'] = "ENOSYS";
callback(err, null);
// TODO: implement file read-write
callback(enosys(), null);
}

read(fd: FileDescriptor, buffer, offset: number, length: number, position: number, callback: NodeCallback<any>) {
const err = new Error("not implemented");
err['code'] = "ENOSYS";
callback(err, null);
callback(enosys(), null);
}

fsync(fd, callback) {
Expand Down
Loading