goserver

package module
v0.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 16 Imported by: 0

README

goserver

Project Badges

Project Badges

goserver

This README documents only the public API exported by the goserver package.

Short summary

  • goserver provides a Config struct and a ServerHandler type. Create a handler with New(*Config) and control a server process using exported methods on ServerHandler.

Public API (types and functions)

  • type Config

    • Fields (public fields used by the package):
      • RootFolder string
      • MainFileWithoutExtension string
      • ArgumentsForCompilingServer func() []string
      • ArgumentsToRunServer func() []string
      • PublicFolder string
      • AppPort string
      • Logger io.Writer
      • ExitChan chan bool
  • type ServerHandler

    • Construct with: New(c *Config) *ServerHandler
    • Exported methods (signatures as found in source):
      • MainInputFileRelativePath() string — returns the path to the generated/external main server file inside the configured RootFolder.
      • Name() string — returns the server name ("GoServer").
      • UnobservedFiles() []string — files that should not be observed by file watchers (executables, temp files).
      • RestartServer() error — restart the external server.
      • StartServer(wg *sync.WaitGroup) — starts the external server; intended to be run as a goroutine and calls wg.Done() when finished.
      • NewFileEvent(fileName, extension, filePath, event string) error — handle file system events; recognized events include create and write for triggering generation/compilation/restart.

Notes and behaviour

  • The package may generate an external server file from embedded templates when the external file is missing. That generation and other internal helpers are not part of the public API (they are unexported).
  • The README intentionally documents only the exported surface. Implementation details, unexported helpers and additional files in templates/ or docs/ are not documented here.

Minimal usage example

package main

import (
		"os"
		"sync"
		"github.com/cdvelop/goserver"
)

func main() {
		cfg := &goserver.Config{
				RootFolder:               "./web",
				MainFileWithoutExtension: "main.server",
				ArgumentsForCompilingServer: func() []string { return []string{} },
				ArgumentsToRunServer:        func() []string { return []string{} },
				PublicFolder:             "public",
				AppPort:                  "8080",
				Logger:                   os.Stdout,
				ExitChan:                 make(chan bool),
		}

		handler := goserver.New(cfg)

		var wg sync.WaitGroup
		wg.Add(1)
		go handler.StartServer(&wg)
		wg.Wait()
}

If you want more documentation about embedded templates or design rationale, consult the templates/ and docs/ folders which contain implementation docs — they are not part of the exported API surface described here.

Contributing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.0.4

type Config struct {
	AppRootDir                  string          // e.g., /home/user/project (application root directory)
	RootFolder                  string          // e.g., web (relative to AppRootDir or absolute path)
	MainFileWithoutExtension    string          // e.g., main.server
	ArgumentsForCompilingServer func() []string // e.g., []string{"-X 'main.version=v1.0.0'"}
	ArgumentsToRunServer        func() []string // e.g., []string{"dev"}
	PublicFolder                string          // e.g., public
	AppPort                     string          // e.g., 8080
	Logger                      io.Writer       // For logging output
	ExitChan                    chan bool       // Global channel to signal shutdown
}

type ServerHandler

type ServerHandler struct {
	*Config
	// contains filtered or unexported fields
}

func New added in v0.0.4

func New(c *Config) *ServerHandler

func (*ServerHandler) MainInputFileRelativePath added in v0.0.21

func (h *ServerHandler) MainInputFileRelativePath() string

MainInputFileRelativePath returns the path relative to AppRootDir (e.g., "pwa/main.server.go")

func (*ServerHandler) NewFileEvent

func (h *ServerHandler) NewFileEvent(fileName, extension, filePath, event string) error

event: create,write,remove,rename

func (*ServerHandler) RestartServer

func (h *ServerHandler) RestartServer() error

func (*ServerHandler) StartServer added in v0.0.6

func (h *ServerHandler) StartServer(wg *sync.WaitGroup)

Start inicia el servidor como goroutine

func (*ServerHandler) SupportedExtensions added in v0.0.22

func (h *ServerHandler) SupportedExtensions() []string

func (*ServerHandler) UnobservedFiles

func (h *ServerHandler) UnobservedFiles() []string

UnobservedFiles returns the list of files that should not be tracked by file watchers eg: main.exe, main_temp.exe

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL