From ad79565a93b84def029a35247615fff3021b318f Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 4 Dec 2023 23:40:41 +0500 Subject: [PATCH] refactor: internal package --- cmd/main.go | 8 ++++---- {config => internal/config}/config.go | 0 {config => internal/config}/config_test.go | 0 {config => internal/config}/load.go | 0 {config => internal/config}/load_test.go | 0 {config => internal/config}/testdata/boxes.json | 0 {config => internal/config}/testdata/commands.json | 0 {config => internal/config}/testdata/config.json | 0 {engine => internal/engine}/docker.go | 8 ++++---- {engine => internal/engine}/docker_test.go | 6 +++--- {engine => internal/engine}/engine.go | 2 +- {engine => internal/engine}/engine_test.go | 0 {engine => internal/engine}/exec.go | 4 ++-- {engine => internal/engine}/exec_test.go | 2 +- {engine => internal/engine}/http.go | 6 +++--- {engine => internal/engine}/http_test.go | 6 +++--- {engine => internal/engine}/io.go | 0 {engine => internal/engine}/io_test.go | 0 {engine => internal/engine}/testdata/example.txt | 0 {execy => internal/execy}/execy.go | 0 {execy => internal/execy}/execy_test.go | 0 {execy => internal/execy}/mock.go | 2 +- {execy => internal/execy}/mock_test.go | 0 {fileio => internal/fileio}/fileio.go | 0 {fileio => internal/fileio}/fileio_test.go | 0 {httpx => internal/httpx}/httpx.go | 0 {httpx => internal/httpx}/httpx_test.go | 0 {httpx => internal/httpx}/mock.go | 0 {httpx => internal/httpx}/mock_test.go | 0 {httpx => internal/httpx}/testdata/example.json | 0 {httpx => internal/httpx}/testdata/example.txt | 0 {logx => internal/logx}/logx.go | 0 {logx => internal/logx}/logx_test.go | 0 {logx => internal/logx}/memory.go | 0 {logx => internal/logx}/memory_test.go | 0 {sandbox => internal/sandbox}/config.go | 4 ++-- {sandbox => internal/sandbox}/config_test.go | 4 ++-- {sandbox => internal/sandbox}/sandbox.go | 2 +- {sandbox => internal/sandbox}/sandbox_test.go | 4 ++-- {sandbox => internal/sandbox}/semaphore.go | 0 {sandbox => internal/sandbox}/semaphore_test.go | 0 {server => internal/server}/io.go | 0 {server => internal/server}/io_test.go | 2 +- {server => internal/server}/middleware.go | 0 {server => internal/server}/middleware_test.go | 0 {server => internal/server}/router.go | 8 ++++---- {server => internal/server}/router_test.go | 8 ++++---- {server => internal/server}/server.go | 2 +- {server => internal/server}/server_test.go | 0 {stringx => internal/stringx}/stringx.go | 0 {stringx => internal/stringx}/stringx_test.go | 0 51 files changed, 39 insertions(+), 39 deletions(-) rename {config => internal/config}/config.go (100%) rename {config => internal/config}/config_test.go (100%) rename {config => internal/config}/load.go (100%) rename {config => internal/config}/load_test.go (100%) rename {config => internal/config}/testdata/boxes.json (100%) rename {config => internal/config}/testdata/commands.json (100%) rename {config => internal/config}/testdata/config.json (100%) rename {engine => internal/engine}/docker.go (97%) rename {engine => internal/engine}/docker_test.go (96%) rename {engine => internal/engine}/engine.go (98%) rename {engine => internal/engine}/engine_test.go (100%) rename {engine => internal/engine}/exec.go (93%) rename {engine => internal/engine}/exec_test.go (97%) rename {engine => internal/engine}/http.go (96%) rename {engine => internal/engine}/http_test.go (97%) rename {engine => internal/engine}/io.go (100%) rename {engine => internal/engine}/io_test.go (100%) rename {engine => internal/engine}/testdata/example.txt (100%) rename {execy => internal/execy}/execy.go (100%) rename {execy => internal/execy}/execy_test.go (100%) rename {execy => internal/execy}/mock.go (95%) rename {execy => internal/execy}/mock_test.go (100%) rename {fileio => internal/fileio}/fileio.go (100%) rename {fileio => internal/fileio}/fileio_test.go (100%) rename {httpx => internal/httpx}/httpx.go (100%) rename {httpx => internal/httpx}/httpx_test.go (100%) rename {httpx => internal/httpx}/mock.go (100%) rename {httpx => internal/httpx}/mock_test.go (100%) rename {httpx => internal/httpx}/testdata/example.json (100%) rename {httpx => internal/httpx}/testdata/example.txt (100%) rename {logx => internal/logx}/logx.go (100%) rename {logx => internal/logx}/logx_test.go (100%) rename {logx => internal/logx}/memory.go (100%) rename {logx => internal/logx}/memory_test.go (100%) rename {sandbox => internal/sandbox}/config.go (93%) rename {sandbox => internal/sandbox}/config_test.go (93%) rename {sandbox => internal/sandbox}/sandbox.go (96%) rename {sandbox => internal/sandbox}/sandbox_test.go (96%) rename {sandbox => internal/sandbox}/semaphore.go (100%) rename {sandbox => internal/sandbox}/semaphore_test.go (100%) rename {server => internal/server}/io.go (100%) rename {server => internal/server}/io_test.go (97%) rename {server => internal/server}/middleware.go (100%) rename {server => internal/server}/middleware_test.go (100%) rename {server => internal/server}/router.go (90%) rename {server => internal/server}/router_test.go (95%) rename {server => internal/server}/server.go (96%) rename {server => internal/server}/server_test.go (100%) rename {stringx => internal/stringx}/stringx.go (100%) rename {stringx => internal/stringx}/stringx_test.go (100%) diff --git a/cmd/main.go b/cmd/main.go index ece9ea7..4b0fd74 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,10 +7,10 @@ import ( "os/signal" "syscall" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/logx" - "github.com/nalgeon/codapi/sandbox" - "github.com/nalgeon/codapi/server" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/logx" + "github.com/nalgeon/codapi/internal/sandbox" + "github.com/nalgeon/codapi/internal/server" ) var Version string = "main" diff --git a/config/config.go b/internal/config/config.go similarity index 100% rename from config/config.go rename to internal/config/config.go diff --git a/config/config_test.go b/internal/config/config_test.go similarity index 100% rename from config/config_test.go rename to internal/config/config_test.go diff --git a/config/load.go b/internal/config/load.go similarity index 100% rename from config/load.go rename to internal/config/load.go diff --git a/config/load_test.go b/internal/config/load_test.go similarity index 100% rename from config/load_test.go rename to internal/config/load_test.go diff --git a/config/testdata/boxes.json b/internal/config/testdata/boxes.json similarity index 100% rename from config/testdata/boxes.json rename to internal/config/testdata/boxes.json diff --git a/config/testdata/commands.json b/internal/config/testdata/commands.json similarity index 100% rename from config/testdata/commands.json rename to internal/config/testdata/commands.json diff --git a/config/testdata/config.json b/internal/config/testdata/config.json similarity index 100% rename from config/testdata/config.json rename to internal/config/testdata/config.json diff --git a/engine/docker.go b/internal/engine/docker.go similarity index 97% rename from engine/docker.go rename to internal/engine/docker.go index d577931..ae20622 100644 --- a/engine/docker.go +++ b/internal/engine/docker.go @@ -13,10 +13,10 @@ import ( "strings" "time" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/execy" - "github.com/nalgeon/codapi/fileio" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/execy" + "github.com/nalgeon/codapi/internal/fileio" + "github.com/nalgeon/codapi/internal/logx" ) var killTimeout = 5 * time.Second diff --git a/engine/docker_test.go b/internal/engine/docker_test.go similarity index 96% rename from engine/docker_test.go rename to internal/engine/docker_test.go index 89dff9b..0322ee9 100644 --- a/engine/docker_test.go +++ b/internal/engine/docker_test.go @@ -4,9 +4,9 @@ import ( "strings" "testing" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/execy" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/execy" + "github.com/nalgeon/codapi/internal/logx" ) var dockerCfg = &config.Config{ diff --git a/engine/engine.go b/internal/engine/engine.go similarity index 98% rename from engine/engine.go rename to internal/engine/engine.go index 0252350..d3d6584 100644 --- a/engine/engine.go +++ b/internal/engine/engine.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/nalgeon/codapi/stringx" + "github.com/nalgeon/codapi/internal/stringx" ) // A Request initiates code execution. diff --git a/engine/engine_test.go b/internal/engine/engine_test.go similarity index 100% rename from engine/engine_test.go rename to internal/engine/engine_test.go diff --git a/engine/exec.go b/internal/engine/exec.go similarity index 93% rename from engine/exec.go rename to internal/engine/exec.go index 7fc0dd2..bb2e8d3 100644 --- a/engine/exec.go +++ b/internal/engine/exec.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "github.com/nalgeon/codapi/execy" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/execy" + "github.com/nalgeon/codapi/internal/logx" ) // A Program is an executable program. diff --git a/engine/exec_test.go b/internal/engine/exec_test.go similarity index 97% rename from engine/exec_test.go rename to internal/engine/exec_test.go index 3771785..be8400a 100644 --- a/engine/exec_test.go +++ b/internal/engine/exec_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/nalgeon/codapi/execy" + "github.com/nalgeon/codapi/internal/execy" ) func TestProgram_Run(t *testing.T) { diff --git a/engine/http.go b/internal/engine/http.go similarity index 96% rename from engine/http.go rename to internal/engine/http.go index 5a0e307..91c3aba 100644 --- a/engine/http.go +++ b/internal/engine/http.go @@ -9,9 +9,9 @@ import ( "net/http" "strings" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/httpx" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/httpx" + "github.com/nalgeon/codapi/internal/logx" ) // An HTTP engine sends HTTP requests. diff --git a/engine/http_test.go b/internal/engine/http_test.go similarity index 97% rename from engine/http_test.go rename to internal/engine/http_test.go index 2961f78..a166aa7 100644 --- a/engine/http_test.go +++ b/internal/engine/http_test.go @@ -5,9 +5,9 @@ import ( "net/http" "testing" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/httpx" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/httpx" + "github.com/nalgeon/codapi/internal/logx" ) var httpCfg = &config.Config{ diff --git a/engine/io.go b/internal/engine/io.go similarity index 100% rename from engine/io.go rename to internal/engine/io.go diff --git a/engine/io_test.go b/internal/engine/io_test.go similarity index 100% rename from engine/io_test.go rename to internal/engine/io_test.go diff --git a/engine/testdata/example.txt b/internal/engine/testdata/example.txt similarity index 100% rename from engine/testdata/example.txt rename to internal/engine/testdata/example.txt diff --git a/execy/execy.go b/internal/execy/execy.go similarity index 100% rename from execy/execy.go rename to internal/execy/execy.go diff --git a/execy/execy_test.go b/internal/execy/execy_test.go similarity index 100% rename from execy/execy_test.go rename to internal/execy/execy_test.go diff --git a/execy/mock.go b/internal/execy/mock.go similarity index 95% rename from execy/mock.go rename to internal/execy/mock.go index a816ad9..20e16a7 100644 --- a/execy/mock.go +++ b/internal/execy/mock.go @@ -4,7 +4,7 @@ import ( "os/exec" "strings" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/logx" ) // Mock installs mock outputs for given commands. diff --git a/execy/mock_test.go b/internal/execy/mock_test.go similarity index 100% rename from execy/mock_test.go rename to internal/execy/mock_test.go diff --git a/fileio/fileio.go b/internal/fileio/fileio.go similarity index 100% rename from fileio/fileio.go rename to internal/fileio/fileio.go diff --git a/fileio/fileio_test.go b/internal/fileio/fileio_test.go similarity index 100% rename from fileio/fileio_test.go rename to internal/fileio/fileio_test.go diff --git a/httpx/httpx.go b/internal/httpx/httpx.go similarity index 100% rename from httpx/httpx.go rename to internal/httpx/httpx.go diff --git a/httpx/httpx_test.go b/internal/httpx/httpx_test.go similarity index 100% rename from httpx/httpx_test.go rename to internal/httpx/httpx_test.go diff --git a/httpx/mock.go b/internal/httpx/mock.go similarity index 100% rename from httpx/mock.go rename to internal/httpx/mock.go diff --git a/httpx/mock_test.go b/internal/httpx/mock_test.go similarity index 100% rename from httpx/mock_test.go rename to internal/httpx/mock_test.go diff --git a/httpx/testdata/example.json b/internal/httpx/testdata/example.json similarity index 100% rename from httpx/testdata/example.json rename to internal/httpx/testdata/example.json diff --git a/httpx/testdata/example.txt b/internal/httpx/testdata/example.txt similarity index 100% rename from httpx/testdata/example.txt rename to internal/httpx/testdata/example.txt diff --git a/logx/logx.go b/internal/logx/logx.go similarity index 100% rename from logx/logx.go rename to internal/logx/logx.go diff --git a/logx/logx_test.go b/internal/logx/logx_test.go similarity index 100% rename from logx/logx_test.go rename to internal/logx/logx_test.go diff --git a/logx/memory.go b/internal/logx/memory.go similarity index 100% rename from logx/memory.go rename to internal/logx/memory.go diff --git a/logx/memory_test.go b/internal/logx/memory_test.go similarity index 100% rename from logx/memory_test.go rename to internal/logx/memory_test.go diff --git a/sandbox/config.go b/internal/sandbox/config.go similarity index 93% rename from sandbox/config.go rename to internal/sandbox/config.go index 925bb06..177ca6f 100644 --- a/sandbox/config.go +++ b/internal/sandbox/config.go @@ -4,8 +4,8 @@ package sandbox import ( "fmt" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/engine" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/engine" ) // A semaphore represents available concurrent workers diff --git a/sandbox/config_test.go b/internal/sandbox/config_test.go similarity index 93% rename from sandbox/config_test.go rename to internal/sandbox/config_test.go index 66255dc..1def702 100644 --- a/sandbox/config_test.go +++ b/internal/sandbox/config_test.go @@ -3,8 +3,8 @@ package sandbox import ( "testing" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/engine" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/engine" ) var cfg = &config.Config{ diff --git a/sandbox/sandbox.go b/internal/sandbox/sandbox.go similarity index 96% rename from sandbox/sandbox.go rename to internal/sandbox/sandbox.go index 7101a33..5654d33 100644 --- a/sandbox/sandbox.go +++ b/internal/sandbox/sandbox.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/nalgeon/codapi/engine" + "github.com/nalgeon/codapi/internal/engine" ) var ErrUnknownSandbox = errors.New("unknown sandbox") diff --git a/sandbox/sandbox_test.go b/internal/sandbox/sandbox_test.go similarity index 96% rename from sandbox/sandbox_test.go rename to internal/sandbox/sandbox_test.go index 6bc0b6b..6a1b9e0 100644 --- a/sandbox/sandbox_test.go +++ b/internal/sandbox/sandbox_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" - "github.com/nalgeon/codapi/engine" - "github.com/nalgeon/codapi/execy" + "github.com/nalgeon/codapi/internal/engine" + "github.com/nalgeon/codapi/internal/execy" ) func TestValidate(t *testing.T) { diff --git a/sandbox/semaphore.go b/internal/sandbox/semaphore.go similarity index 100% rename from sandbox/semaphore.go rename to internal/sandbox/semaphore.go diff --git a/sandbox/semaphore_test.go b/internal/sandbox/semaphore_test.go similarity index 100% rename from sandbox/semaphore_test.go rename to internal/sandbox/semaphore_test.go diff --git a/server/io.go b/internal/server/io.go similarity index 100% rename from server/io.go rename to internal/server/io.go diff --git a/server/io_test.go b/internal/server/io_test.go similarity index 97% rename from server/io_test.go rename to internal/server/io_test.go index 13e061d..78cf0b1 100644 --- a/server/io_test.go +++ b/internal/server/io_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/nalgeon/codapi/engine" + "github.com/nalgeon/codapi/internal/engine" ) func Test_readJson(t *testing.T) { diff --git a/server/middleware.go b/internal/server/middleware.go similarity index 100% rename from server/middleware.go rename to internal/server/middleware.go diff --git a/server/middleware_test.go b/internal/server/middleware_test.go similarity index 100% rename from server/middleware_test.go rename to internal/server/middleware_test.go diff --git a/server/router.go b/internal/server/router.go similarity index 90% rename from server/router.go rename to internal/server/router.go index 99b6820..ae5e776 100644 --- a/server/router.go +++ b/internal/server/router.go @@ -6,10 +6,10 @@ import ( "fmt" "net/http" - "github.com/nalgeon/codapi/engine" - "github.com/nalgeon/codapi/logx" - "github.com/nalgeon/codapi/sandbox" - "github.com/nalgeon/codapi/stringx" + "github.com/nalgeon/codapi/internal/engine" + "github.com/nalgeon/codapi/internal/logx" + "github.com/nalgeon/codapi/internal/sandbox" + "github.com/nalgeon/codapi/internal/stringx" ) // NewRouter creates HTTP routes and handlers for them. diff --git a/server/router_test.go b/internal/server/router_test.go similarity index 95% rename from server/router_test.go rename to internal/server/router_test.go index 78b0087..6c04cc2 100644 --- a/server/router_test.go +++ b/internal/server/router_test.go @@ -7,10 +7,10 @@ import ( "net/http/httptest" "testing" - "github.com/nalgeon/codapi/config" - "github.com/nalgeon/codapi/engine" - "github.com/nalgeon/codapi/execy" - "github.com/nalgeon/codapi/sandbox" + "github.com/nalgeon/codapi/internal/config" + "github.com/nalgeon/codapi/internal/engine" + "github.com/nalgeon/codapi/internal/execy" + "github.com/nalgeon/codapi/internal/sandbox" ) var cfg = &config.Config{ diff --git a/server/server.go b/internal/server/server.go similarity index 96% rename from server/server.go rename to internal/server/server.go index 9f0b094..b377871 100644 --- a/server/server.go +++ b/internal/server/server.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "github.com/nalgeon/codapi/logx" + "github.com/nalgeon/codapi/internal/logx" ) // The maximum duration of the server graceful shutdown. diff --git a/server/server_test.go b/internal/server/server_test.go similarity index 100% rename from server/server_test.go rename to internal/server/server_test.go diff --git a/stringx/stringx.go b/internal/stringx/stringx.go similarity index 100% rename from stringx/stringx.go rename to internal/stringx/stringx.go diff --git a/stringx/stringx_test.go b/internal/stringx/stringx_test.go similarity index 100% rename from stringx/stringx_test.go rename to internal/stringx/stringx_test.go