Skip to content

Commit

Permalink
Some more serialization types and fleshed out the idea some more
Browse files Browse the repository at this point in the history
  • Loading branch information
p0t4t0sandwich committed May 7, 2024
1 parent 9ded344 commit 6808121
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 10 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
)

require (
github.com/badgerodon/collections v0.0.0-20220321173820-f0935ab71cd6 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -34,6 +35,7 @@ require (
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tidwall/btree v1.2.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/ZeroErrors/go-bedrockping v1.0.0 h1:nCAkSohHa9c/Gk8klpwBueiJQHOWz2aMKgF1iOLhgko=
github.com/ZeroErrors/go-bedrockping v1.0.0/go.mod h1:JQdyrc0ScjiSi8O0mbRxMyWQ3fnXrTgMApB/9HOmVPQ=
github.com/badgerodon/collections v0.0.0-20220321173820-f0935ab71cd6 h1:6E3UhqBf8Ca3Xw1+6co6d0iVg9zmvRI9eznDjSzU0uE=
github.com/badgerodon/collections v0.0.0-20220321173820-f0935ab71cd6/go.mod h1:o9BQhMI/mZs1OE+PhAraPMAEuIVkn7QVVU0HMLQQcmQ=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
Expand Down Expand Up @@ -66,6 +68,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/btree v1.2.0 h1:cXmC8TB0xxua4tmOf+cLhi4KE59e2075IXB/KRjEhYQ=
github.com/tidwall/btree v1.2.0/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down Expand Up @@ -103,6 +107,7 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
15 changes: 15 additions & 0 deletions modules/archive/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package archive

import (
"net/http"

"github.com/NeuralNexusDev/neuralnexus-api/modules/database"
)

// ApplyRoutes - Apply routes to the router
func ApplyRoutes(router *http.ServeMux) *http.ServeMux {
bucket := NewS3Store(database.GetS3())
bucket.MakeBucket()
service := NewService(bucket)
return router
}
30 changes: 30 additions & 0 deletions modules/archive/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,33 @@ func NewSpongePlugin(spongePluginsJSON string) (*SpongePlugin, error) {
}
return plugin, nil
}

type (
// VelocityPlugin is a struct that represents the velocity-plugin.json file of a Velocity plugin
VelocityPlugin struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
URL string `json:"url"`
Authors []string `json:"authors"`
Dependencies []VelocityDependency `json:"dependencies"`
Main string `json:"main"`
}

// VelocityDependency is a struct that represents a dependency of a Velocity plugin
VelocityDependency struct {
ID string `json:"id"`
Optional bool `json:"optional"`
}
)

// NewVelocityPlugin creates a new VelocityPlugin struct from the velocity-plugin.json file
func NewVelocityPlugin(velocityJSON string) (*VelocityPlugin, error) {
plugin := &VelocityPlugin{}
err := json.Unmarshal([]byte(velocityJSON), plugin)
if err != nil {
return nil, err
}
return plugin, nil
}
19 changes: 19 additions & 0 deletions modules/archive/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package archive

// Service interface for the archive service
type Service interface{}

// service implementation of the archive service
type service struct {
store S3Store
}

// NewService creates a new archive service
func NewService(store S3Store) Service {
return &service{store}
}

// PluginMod interface for a plugin/mod that can be converted to an MCMod
type PluginMod interface {
ToMCMod(s Service) *MCMod
}
54 changes: 44 additions & 10 deletions modules/archive/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,55 @@ package archive

// ArchiveItem is a struct that represents an item in the archive
type ArchiveItem struct {
ID string `json:"id"`
Name string `json:"name"`
Endpoint string `json:"endpoint"`
Size int64 `json:"size"`
Links []Link `json:"links"`
ID string `db:"id" json:"id" xml:"id"`
FileName string `db:"file_name" json:"file_name" xml:"file_name"`
Size int64 `db:"size" json:"size" xml:"size"`
MD5 string `db:"md5" json:"md5" xml:"md5"`
SHA1 string `db:"sha1" json:"sha1" xml:"sha1"`
SHA256 string `db:"sha256" json:"sha256" xml:"sha256"`
SHA512 string `db:"sha512" json:"sha512" xml:"sha512"`
Related []string `db:"related" json:"related" xml:"related"`
Links []Link `db:"links" json:"links" xml:"links"`
}

// Link is a struct that represents external links
type Link struct {
Rel string `json:"rel"`
Href string `json:"href"`
Rel string `db:"rel" json:"rel" xml:"rel"`
Href string `db:"href" json:"href" xml:"href"`
}

// MinecraftMod is a struct that represents a Minecraft mod
type MinecraftMod struct {
// MCMod is a struct that represents a Minecraft mod
type MCMod struct {
ArchiveItem
ModID string `json:"mod_id"`
ModID string `db:"mod_id" json:"mod_id" xml:"mod_id"`
Name string `db:"name" json:"name" xml:"name"`
Authors []string `db:"authors" json:"authors" xml:"authors"`
Contributors []string `db:"contributors" json:"contributors" xml:"contributors"`
Platforms []ModPlatform `db:"platforms" json:"platforms" xml:"platforms"`
Dependencies []MCModDependency `db:"dependencies" json:"dependencies" xml:"dependencies"`
}

// ModPlatform is a type that represents a platform for a Minecraft mod
type ModPlatform string

const (
// ModPlatformBukkit is the Bukkit platform
ModPlatformBukkit ModPlatform = "bukkit"
// ModPlatformBungeeCord is the BungeeCord platform
ModPlatformBungeeCord ModPlatform = "bungeecord"
// ModPlatformForge is the Forge platform
ModPlatformForge ModPlatform = "forge"
// ModPlatformFabric is the Fabric platform
ModPlatformFabric ModPlatform = "fabric"
// ModPlatformSponge is the Sponge platform
ModPlatformSponge ModPlatform = "sponge"
// ModPlatformVelocity is the Velocity platform
ModPlatformVelocity ModPlatform = "velocity"
)

// MCModDependency is a struct that represents a dependency of a Minecraft mod
type MCModDependency struct {
ID string `db:"id" json:"id" xml:"id"`
Required bool `db:"required" json:"required" xml:"required"`
Version string `db:"version" json:"version" xml:"version"`
}

0 comments on commit 6808121

Please sign in to comment.