clay

package module
v0.0.0-...-e3d5971 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: MIT Imports: 3 Imported by: 0

README

clay

[Experimental] lightweight framework for writing cloudflare workers with go

//go:build js && wasm
// +build js,wasm

package main

import (
 "github.com/uchexgod/clay"
)

func main() {

  app := clay.NewApp()

 //send html response
  app.Get("/", func(ctx *clay.Context, next clay.NextFunc) interface{} {

  htmlContent := `
    <!DOCTYPE html>
    <html>
    <head>
    <title>To-Do List</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        #todoInput { padding: 10px; width: 200px; margin-right: 10px; }
        #addButton { padding: 10px; }
        #todoList { margin-top: 20px; }
    </style>
    </head>
    <body>
        <input type="text" id="todoInput" placeholder="Add a new task">
        <button id="addButton">Add Task</button>
        <ul id="todoList"></ul>
        
        <script>
            document.getElementById("addButton").onclick = function() {
                var input = document.getElementById("todoInput");
                var newTodo = input.value;
                if (newTodo) {
                    var li = document.createElement("li");
                    li.textContent = newTodo;
                    document.getElementById("todoList").appendChild(li);
                    input.value = ""; // Clear the input
                }
            };
        </script>
    </body>
    </html>
    `
  return ctx.HTML(htmlContent)
 })

 //send text response
 app.Post("/todo", func(ctx *clay.Context, next clay.NextFunc) interface{} {
  return ctx.Text("Todo Created", 201)
 })


 app.Listen()

}



## Todo

- [ ] Request 
- [ ] Context
- [ ] Kv & D1

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApp

func NewApp() *app

Types

type Context

type Context struct {
	Request *Request
}

func (*Context) HTML

func (res *Context) HTML(htmlString string, status ...int) Response

func (*Context) JSON

func (ctx *Context) JSON(v map[string]string, status ...int) Response

func (*Context) Redirect

func (ctx *Context) Redirect(destination string, status ...int) Response

func (*Context) Text

func (ctx *Context) Text(content interface{}, status ...int) Response

type Handler

type Handler func(ctx *Context, next NextFunc) Response

type NextFunc

type NextFunc func(ctx *Context)

type RegexpRouter

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

func NewRegexpRouter

func NewRegexpRouter() *RegexpRouter

func (*RegexpRouter) Register

func (r *RegexpRouter) Register(method, pattern string, handler Handler)

func (*RegexpRouter) ServeHTTP

func (r *RegexpRouter) ServeHTTP(this js.Value, args []js.Value) interface{}

type Request

type Request struct {
	Method string
	// contains filtered or unexported fields
}

func (*Request) Body

func (r *Request) Body() map[string]string

func (*Request) Header

func (r *Request) Header(name string) string

func (*Request) Headers

func (r *Request) Headers(name string) map[string]string

func (*Request) Param

func (r *Request) Param(name string) string

func (*Request) Queries

func (r *Request) Queries() map[string]string

func (*Request) Query

func (r *Request) Query(name string) string

func (*Request) Text

func (r *Request) Text() (body string)

type Response

type Response struct {
	Body    interface{}
	Headers map[string]interface{}
	Status  int
}

type Route

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

Directories

Path Synopsis
example
compose command

Jump to

Keyboard shortcuts

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