{"id":18683499,"url":"https://github.com/narasimha1997/gopg","last_synced_at":"2025-07-19T04:35:03.355Z","repository":{"id":55509415,"uuid":"324179819","full_name":"Narasimha1997/gopg","owner":"Narasimha1997","description":"A minimal microservice written in Go that executes Go programs. This microservice can be used to set-up local go learning environment at your workspace/school. You can also use the provided zero-configuration docker-image for quick deployments.","archived":false,"fork":false,"pushed_at":"2021-01-18T03:26:01.000Z","size":25,"stargazers_count":29,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T04:40:31.984Z","etag":null,"topics":["academia","academic","docker","go","golang","learning","microservice","rest-api","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Narasimha1997.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-24T14:59:17.000Z","updated_at":"2025-02-11T02:38:48.000Z","dependencies_parsed_at":"2022-08-15T02:01:13.529Z","dependency_job_id":null,"html_url":"https://github.com/Narasimha1997/gopg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Narasimha1997/gopg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fgopg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fgopg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fgopg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fgopg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Narasimha1997","download_url":"https://codeload.github.com/Narasimha1997/gopg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fgopg/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265889120,"owners_count":23844539,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["academia","academic","docker","go","golang","learning","microservice","rest-api","tutorial"],"created_at":"2024-11-07T10:14:47.364Z","updated_at":"2025-07-19T04:35:03.335Z","avatar_url":"https://github.com/Narasimha1997.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### gopg\nA minimal microservice written in Go that executes Go programs. This microservice can be used to set-up local go learning environment at your workspace/school. The tool comes with an optional secure sandbox powered by gVisor and Docker.\n\n#### Features:\n1. Zero-dependencies.\n2. Simple POST APIs to execute from JSON or File.\n3. A built-in work-queue that takes care of parallelizing execution work-loads.\n4. Auto-suspension of executions taking more than 10 seconds - avoids infinite looping.\n5. Easily deployable using docker image.\n6. Secure sandbox which executes the programs in an isolated environment. \n\n### Using gopg\nThere are two ways you can use `gopg`:\n\nRequirements:\n1. Golang 1.5+\n2. GCC compiler\n3. Docker installed and configured.\n4. `runsc` - gVisor runtime pluin for docker, you can install it by running `scripts/install_runsc.sh`\n\n#### 1. Local Setup\nTo build and use gopg locally, go to `./scripts` and run:\n```\ncd scripts/\n./build_sandbox.sh\n```\nThen you can run `gopg` as :\n```\n./bin/gopg\n```\n\n#### 2. Docker-setup\nTo run the entire environment inside a docker container, run the same command with `--docker` option.\n```\ncd scripts/\n./build_sandbox.sh --docker\n```\n\nThen you can start the container as follows: (you need to pass docker socket file to the container)\n```\ndocker run -ti -v /var/run/docker.sock:/var/run/docker.sock --net=host gopg\n```\n\n#### Enabling Sandboxed mode\nThe sandbox mode can be enabled/disabled whenever required. (Note : Running without sandbox can execute the binary directly on your host kernel and has access to the host-file system which is not recommended). In some scenarios, you may need not have to worry about security, in such cases you can turn off the sandbox. If you need all the security features to be available, you can enable sandbox (Note : Sandboxed mode introduces more latency because the container needs to be created with gVisor runtime everytime you execute the program). \n\nTo enable sandbox, you can set `SANDBOX=1` environment variable, `gopg` sees this environment variable to decide whether to run sandbox or not. \n\nLocally:\n```\nexport SANDBOX=1\n./bin/gopg\n```\n\nDocker:\n```\ndocker run -ti -v /var/run/docker.sock:/var/run/docker.sock --net=host --env=\"SANDBOX=1\" gopg\n```\n\n#### Example API usage\nThe API `/executeJSON` can be used to execute go-programs. Let's create a simple json structure like the one shown below (example.json):\n\n```json\n{\n    \"program\" : \"package main\\n\\nimport \\\"fmt\\\"\\n\\nfunc main() {\\n fmt.Println(\\\"Hello, world!\\\")\\n\\n }\"\n}\n```\n\nAnd use curl to send a json request\n```\ncurl -X POST -H \"Content-Type: application/json\" -d @./examples/example.json http://localhost:9000/executeJson | json_pp\n```\n\nYou should see the following output:\n```json\n{\n   \"error\" : false,\n   \"errorString\" : \"\",\n   \"execution\" : {\n      \"output\" : \"Hello, world!\\n\",\n      \"executionTime\" : 0.196068332,\n      \"success\" : true\n   }\n}\n```\nThe keys `error` and `errorString` will contain API errors, the output information can be found inside `execution` key. The `output` contains output string or the error string in case of runtime/syntax errors. The `executionTime` key says the execution time in seconds and finally the `success` key will say if the program executed successfully or encountered an error.\n\nYou can also use the File API which takes `multipart/form-data` as input and provides the result. Let's create a file called `example.go` under `examples`:\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello, world!!\")\n}\n\n```\n\nNow we can send `multipart/form-data` to the server, using `curl`\n\n```\ncurl -F file=@./examples/example.go -H \"Content-Type:multipart/form-data\" http://localhost:9000/executeFile | json_pp\n```\n\nYou can see the output exactly like the previous case:\n```json\n{\n   \"execution\" : {\n      \"output\" : \"Hello, world!!\\n\",\n      \"executionTime\" : 0.220491135,\n      \"success\" : true\n   },\n   \"error\" : false,\n   \"errorString\" : \"\"\n}\n```\n\n#### Using client-binary\n`./script/build_client.sh` builds client binary. The client binary executes go-programs by making request to the server. You can use the client binary as follows:\n\n```\n./bin/gopg-client ./examples/example.go\n```\n\nIf everything worked as expected, it should produce the output as shown below:\n\n```\nServer Status:\n-------------------\n Server successfully processed your file\n\n============================================================\nProgram output:\n-------------------\n Hello, world!!\n\n\n============================================================\nCompile + Execution time:\n------------------- \n0.554610\n```\n\n#### Contributing\nContributions are always welcome. You can raise an issue or contribute new features by making a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarasimha1997%2Fgopg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarasimha1997%2Fgopg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarasimha1997%2Fgopg/lists"}