wx

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 15 Imported by: 0

README

wx

wx

wx is an open-source framework that allows you to quickly build Go apps that use Svelte for rendering web pages.

This project was heavily inspired by bud. wx tries to be less opinionated about your Go app build process.

IMPORTANT!

This project is at the very early stage. Do not use it for production! Wait until v1 is released.

Usage

Installation
go get github.com/apack/wx
go install github.com/apack/wx/cmd/...
Initialize Views

Open your Go app folder and initialize views.

wx init

This will create files:

app
├── app.wx.go
├── components
│   ├── Button.svelte
│   └── Counter.svelte
├── gen.go
├── layouts
│   └── DefaultLayout.svelte
├── static
│   └── logo.svg
└── views
    └── WelcomeView.svelte

NOTE: Every time you change these files run go generate ./app.

Create Server

Load your app and add handler.

package main

import (
	"net/http"
	"your/path/to/app"

	"github.com/apack/wx"
)

func main() {
	web := wx.NewRouter()
	err := app.Load(web)
	if err != nil {
		panic(err)
	}
	web.HandleMethodFunc("GET", "/", handleWelcomeView())
	http.ListenAndServe(":8080", web)
}

func handleWelcomeView() wx.HandlerFunc {
	return func(ctx *wx.Context) error {
		return ctx.View(app.WelcomeView, wx.Props{
			"count": 111,
		})
	}
}

Roadmap

These are the main accomplishments that I want to release with future versions.

v0.1 - Done
  • Create concept and release it to the public
v0.2 - WIP
  • Improve view renderer.
v0.3
  • Improve router.
  • Add middlewares for CORS, Caching and Compression.
v0.4
  • Make project ready for community contributions.
v0.5
  • Add TypeScript support for Svelte components.
  • Add SASS support for Svelte components.
  • Add Markdown support for static content.
v0.6
  • Fix memory issue with long-lived v8 isolates. v8go#105
v0.7
  • Create documentation and landing pages using wx.

Contributing

Project is not ready to accept contributors yet. Wait until v0.4 when all of the development documentation and CI is finished.

Credits

This work is based off the existing frameworks:

License

Copyright (c) 2022-present APack and Contributors. wx is free and open-source software licensed under the MIT License.

Third-party library licenses:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(dir string) error

Types

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func (*Context) JSON

func (ctx *Context) JSON(v interface{}) error

func (*Context) Method

func (ctx *Context) Method() string

func (*Context) ParseForm

func (ctx *Context) ParseForm() (url.Values, error)

func (*Context) Path

func (ctx *Context) Path() string

func (*Context) Query

func (ctx *Context) Query() url.Values

func (*Context) Redirect

func (ctx *Context) Redirect(url string, code int) error

func (*Context) Status

func (ctx *Context) Status(code int) *Context

func (*Context) View

func (ctx *Context) View(view View, props Props) error

type Handler

type Handler interface {
	HandleWeb(ctx *Context) error
}

type HandlerFunc

type HandlerFunc func(ctx *Context) error

func (HandlerFunc) HandleWeb

func (f HandlerFunc) HandleWeb(ctx *Context) error

type Middleware

type Middleware func(Handler) Handler

type Props

type Props map[string]interface{}

type RenderEngine

type RenderEngine struct {
	// contains filtered or unexported fields
}

func NewRenderEngine

func NewRenderEngine() *RenderEngine

func (*RenderEngine) Close

func (e *RenderEngine) Close()

func (*RenderEngine) RegisterViews

func (e *RenderEngine) RegisterViews(views ...View) error

func (*RenderEngine) Render

func (e *RenderEngine) Render(view View, props Props) ([]byte, error)

type RenderWorker

type RenderWorker struct {
	// contains filtered or unexported fields
}

func NewRenderWorker

func NewRenderWorker(view View) (*RenderWorker, error)

func (*RenderWorker) Close

func (w *RenderWorker) Close() error

func (*RenderWorker) Render

func (w *RenderWorker) Render(props Props) ([]byte, error)

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(view View) (*Renderer, error)

func (*Renderer) Close

func (r *Renderer) Close() error

func (*Renderer) Render

func (r *Renderer) Render(props Props) ([]byte, error)

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) Handle

func (r *Router) Handle(path string, h Handler)

func (*Router) HandleFunc

func (r *Router) HandleFunc(path string, h HandlerFunc)

func (*Router) HandleMethod

func (r *Router) HandleMethod(method, path string, h Handler)

func (*Router) HandleMethodFunc

func (r *Router) HandleMethodFunc(method, path string, h HandlerFunc)

func (*Router) RegisterViews

func (r *Router) RegisterViews(views ...View) error

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Static

func (r *Router) Static(files fs.FS) error

func (*Router) Use

func (r *Router) Use(mws ...Middleware)

type View

type View interface {
	Name() string
	DOM() *ViewDOM
	CSS() *ViewCSS
	SSR() *ViewSSR
}

type ViewCSS

type ViewCSS struct {
	FileName string
	Style    []byte
}

type ViewDOM

type ViewDOM struct {
	FileName string
	Script   []byte
}

type ViewRegistry

type ViewRegistry interface {
	RegisterViews(views ...View) error
}

type ViewSSR

type ViewSSR struct {
	Script []byte
}

Directories

Path Synopsis
cmd
wx
app
internal
dag
js
ssr

Jump to

Keyboard shortcuts

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