Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Refactoring to let gopypi be more extendable #2

Closed
wants to merge 13 commits into from
Closed
29 changes: 29 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# User managed exclusions
.github/
bin/
31 changes: 14 additions & 17 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.15
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.16
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Get dependencies
run: |
go get -v -t -d ./...

- name: Build local gopypi
run: go build -o gopypi-local -v cmd/local/main.go
- name: Build
run: go build ./...

- name: Build gopypi
run: go build -o gopypi -v cmd/gcs/main.go

- name: Test
run: go test -v ./...
- name: Test
run: go test -v ./...
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ modules.xml
# End of https://www.toptal.com/developers/gitignore/api/intellij+all,go

# User custom .gitignore
credentials/
credentials/
bin/
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build:
go build -o bin/registry cmd/registry/main.go

build-all:
echo "Compiling for every OS and Platform"
GOOS=windows GOARCH=amd64 go build -o bin/registry-windows-amd64 cmd/registry/main.go
GOOS=linux GOARCH=arm go build -o bin/registry-linux-arm cmd/registry/main.go
GOOS=linux GOARCH=arm64 go build -o bin/registry-linux-arm64 cmd/registry/main.go
GOOS=freebsd GOARCH=386 go build -o bin/registry-freebsd-386 cmd/registry/main.go
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ go install -o gopypi-gcs cmd/gcs/main.go
Simple static file server exposing packages locally.

```bash
$ ./gopypi-local -help
Usage of C:\GithubTech\go\src\github.com\MadJlzz\gopypi\gopypi-local:
$ ./gopypi-file-server -help
Usage of C:\GithubTech\go\src\github.com\MadJlzz\gopypi\gopypi-file-server:
-package-location string
Location from which we should load packages. (default "C:/DefaultStorage")
-port string
Expand Down
6 changes: 6 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
runtime: go115

service: gopypi
main: ./cmd/registry/main.go

service_account: [email protected]
44 changes: 0 additions & 44 deletions cmd/gcs/main.go

This file was deleted.

44 changes: 0 additions & 44 deletions cmd/local/main.go

This file was deleted.

43 changes: 43 additions & 0 deletions cmd/registry/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"context"
"github.com/MadJlzz/gopypi/internal/http/rest"
"github.com/MadJlzz/gopypi/internal/storage/gcs"
"go.uber.org/zap"
"log"
"net/http"
"os"
)

func main() {
l, err := zap.NewDevelopment()
if err != nil {
log.Fatalf("can't initialize zap l: %v", err)
}
defer l.Sync()

// SugaredLogger includes both printf-style APIs.
logger := l.Sugar()

port := os.Getenv("PORT")
if port == "" {
port = "8080"
logger.Infof("Defaulting to port %s", port)
}

ctx := context.Background()

// TODO: use a factory to retrieve the correct storage and be more flexible.
storage := gcs.NewStorage(ctx, logger, "gopypi")
logger.Infof("new connection with storage backend [%v]", storage)

// set up HTTP server
ph := rest.NewRepositoryHandler(logger, storage)
router := ph.Router(ctx)

logger.Info("The PyPi server is live: http://localhost:8080")
if err := http.ListenAndServe(":"+port, router); err != nil {
logger.Fatal(err)
}
}
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module github.com/MadJlzz/gopypi

go 1.15
go 1.16

require (
cloud.google.com/go v0.67.0 // indirect
cloud.google.com/go/storage v1.12.0
cloud.google.com/go v0.89.0
cloud.google.com/go/storage v1.16.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/gorilla/mux v1.8.0
github.com/sirupsen/logrus v1.7.0
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c // indirect
golang.org/x/tools v0.0.0-20200929223013-bf155c11ec6f // indirect
google.golang.org/api v0.32.0
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
google.golang.org/api v0.52.0
google.golang.org/genproto v0.0.0-20210729151513-df9385d47c1b
)
Loading