server

package module
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 15 Imported by: 0

README

goserver

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):
      • AppRootDir string
      • SourceDir string
      • OutputDir string
      • ArgumentsForCompilingServer func() []string
      • ArgumentsToRunServer func() []string
      • AppPort string
      • Logger func(message ...any)
      • ExitChan chan bool
  • func NewConfig() *Config — returns a new Config with sensible default values

  • 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 SourceDir.
      • 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 (
		"fmt"
		"os"
		"sync"
		"github.com/tinywasm/server"
)

func main() {
		cfg := &goserver.Config{
				AppRootDir:               ".",
				SourceDir:                "src/cmd/appserver",
				OutputDir:                "deploy/appserver",
				ArgumentsForCompilingServer: func() []string { return []string{} },
				ArgumentsToRunServer:        func() []string { return []string{} },
				AppPort:                  "8080",
				Logger:                   func(messages ...any) { fmt.Fprintln(os.Stdout, messages...) },
				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

type Config struct {
	AppRootDir                  string               // e.g., /home/user/project (application root directory)
	SourceDir                   string               // directory location of main.go e.g., src/cmd/appserver (relative to AppRootDir)
	OutputDir                   string               // compilation and execution directory e.g., deploy/appserver (relative to AppRootDir)
	PublicDir                   string               // default public dir for generated server (e.g., src/web/public)
	MainInputFile               string               // main input file name (default: "main.go", can be "server.go", etc.)
	ArgumentsForCompilingServer func() []string      // e.g., []string{"-X 'main.version=v1.0.0'"}
	ArgumentsToRunServer        func() []string      // e.g., []string{"dev"}
	AppPort                     string               // e.g., 8080
	Logger                      func(message ...any) // For logging output
	ExitChan                    chan bool            // Global channel to signal shutdown
}

func NewConfig

func NewConfig() *Config

NewConfig provides a default configuration.

type ServerHandler

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

func New

func New(c *Config) *ServerHandler

func (*ServerHandler) MainInputFileRelativePath

func (h *ServerHandler) MainInputFileRelativePath() string

MainInputFileRelativePath returns the path relative to AppRootDir (e.g., "src/cmd/appserver/main.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

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

Start inicia el servidor como goroutine

func (*ServerHandler) SupportedExtensions

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