Skip to content

Commit

Permalink
refactor: Move generated code to api package
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikelVeen committed Jun 23, 2024
1 parent 842a9e9 commit 433a728
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 33 deletions.
4 changes: 2 additions & 2 deletions server/server.gen.go → api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@ func Execute() {
}

func init() {
//
// Add commands to the root command.
//
rootCmd.AddCommand(NewConvertCommand().Command)
rootCmd.AddCommand(NewDocsCommand().Command)
rootCmd.AddCommand(server.NewCommand().Command)

//
// Register flags.
//

pflags := rootCmd.PersistentFlags()

pflags.BoolP(ArgsVerbose, ArgsVerboseShorthand, false, "Enable verbose output")
Expand All @@ -58,6 +52,7 @@ func initializeConfig(cmd *cobra.Command) error {

v.SetConfigName(defaultConfigFilename)
v.AddConfigPath(".")
// Add glasscms config directory to the search path.

var cfgNotFoundError viper.ConfigFileNotFoundError
if err := v.ReadInConfig(); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package server

import (
"github.com/glass-cms/glasscms/database"
"github.com/spf13/cobra"
)

type Config struct {
Database *database.Config `mapstructure:"database"`
}

type Command struct {
Command *cobra.Command
}
Expand Down
4 changes: 2 additions & 2 deletions codegen-server.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: server
package: api
generate:
std-http-server: true
models: true
output: server/server.gen.go
output: api/api.gen.go
5 changes: 4 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
output: ./out/
output: ./out/
database:
driver: sqlite3

8 changes: 4 additions & 4 deletions database/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ var (
// Config represents the configuration for a database connection.
type Config struct {
// Driver is the name of the database driver.
Driver string
Driver string `mapstructure:"driver"`

// DSN is the Data Source Name. It specifies the username, password, and database name
// that are used to connect to the database.
DSN string
DSN string `mapstructure:"dsn"`

// MaxConnection is the maximum number of connections that can be opened to the database.
MaxConnections int
MaxConnections int `mapstructure:"max_connections"`

// MaxIdleConnections is the maximum number of idle connections that can be maintained.
// Idle connections are connections that are open but not in use.
MaxIdleConnections int
MaxIdleConnections int `mapstructure:"max_idle_connections"`
}

// NewConnection creates a new database connection using the provided configuration.
Expand Down
1 change: 0 additions & 1 deletion item/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const (
type Item struct {
UID string `json:"uid" yaml:"uid"`
// Name is the full resource name of the item.
// Format: collections/{collection}/items/{item}
Name string `json:"name" yaml:"name"`
DisplayName string `json:"display_name" yaml:"display_name"`
Path string `json:"path" yaml:"path"`
Expand Down
18 changes: 18 additions & 0 deletions server/item.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package server

import "net/http"

func (s *Server) ItemsDelete(w http.ResponseWriter, _ *http.Request) {
// TODO.
w.WriteHeader(http.StatusNotImplemented)
}

func (s *Server) ItemsList(w http.ResponseWriter, _ *http.Request) {
// TODO.
w.WriteHeader(http.StatusNotImplemented)
}

func (s *Server) ItemsCreate(w http.ResponseWriter, _ *http.Request) {
// TODO.
w.WriteHeader(http.StatusNotImplemented)
}
21 changes: 4 additions & 17 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"log/slog"
"net/http"
"time"

"github.com/glass-cms/glasscms/api"
)

const (
Expand All @@ -20,7 +22,7 @@ type Server struct {
server *http.Server
}

var _ ServerInterface = (*Server)(nil)
var _ api.ServerInterface = (*Server)(nil)

func New(
logger *slog.Logger,
Expand All @@ -31,7 +33,7 @@ func New(
}

server.server = &http.Server{
Handler: HandlerFromMux(server, http.NewServeMux()),
Handler: api.HandlerFromMux(server, http.NewServeMux()),
Addr: fmt.Sprintf(":%v", DefaultPort),
ReadTimeout: DefaultReadTimeout,
WriteTimeout: DefaultWriteTimeout,
Expand Down Expand Up @@ -64,18 +66,3 @@ func (s *Server) Shutdown() {

s.logger.Info("server stopped")
}

func (s *Server) ItemsDelete(w http.ResponseWriter, _ *http.Request) {
// TODO.
w.WriteHeader(http.StatusNotImplemented)
}

func (s *Server) ItemsList(w http.ResponseWriter, _ *http.Request) {
// TODO.
w.WriteHeader(http.StatusNotImplemented)
}

func (s *Server) ItemsCreate(w http.ResponseWriter, _ *http.Request) {
// TODO.
w.WriteHeader(http.StatusNotImplemented)
}

0 comments on commit 433a728

Please sign in to comment.