volts

package module
v0.0.0-...-5e9c659 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Warning: This package is a work in progress. After some preliminary testing, I think I might change a lot of how this package is structured.

volts.dev

a golang web+rpc framework

框架提供关于Http服务器端最精简逻辑实现,理论上可以兼容大部分其他框架中间件(需要小量修改)

QQ Group 151120790

服务器目录树
App
│
├─module 应用模块目录
│  ├─web 模块目录
│  │  ├─static 静态资源目录
│  │  │   ├─uploads 上传根目录
│  │  │   ├─lib 资源库文件目录(常用作前端框架库)
│  │  │   └─src 资源文件
│  │  │      ├─js 资源Js文件目录
│  │  │      ├─img 资源图片文件目录
│  │  │      └─css 资源Css文件
│  │  ├─model 模型目录
│  │  ├─template 视图文件目录
│  │  ├─data 数据目录
│  │  ├─model 模型目录
│  │  └─controller.go 控制器
│  │
│  ├─base 模块目录
│  │
│  └─... 扩展的可装卸功能模块或插件
│
├─static 静态资源目录
│  ├─uploads 上传根目录
│  ├─lib 资源库文件目录(常用作前端框架库)
│  └─src 资源文件
│     ├─js 资源Js文件目录
│     ├─img 资源图片文件目录
│     └─css 资源Css文件
├─template 视图文件目录
├─deploy 部署文件目录
│
├─main.go 主文件
└─main.ini 配置文件

hello world demo

package main

import (
	"fmt"
	"github.com/volts-dev/volts/server"
)

type (
	ctrls struct {
	}
)

func (self ctrls) hello_world(hd *server.THandler) {
	hd.RespondString("Hello volts.dev World!")
}

func main() {
	srv := server.NewServer("name")
	srv.Url("Get","/hello", ctrls.hello_world)
	srv.Url("Get","/hello2", func(c *web.THandler) {
		c.RespondString("Hello, World")
		return
	})

	srv.Url("Get","/hello3", func(c *server.THandler) {
		c.RenderTemplate("hello_world.html", map[string]interface{}{"static": "youpath"})
		fmt.Println("b", c.Route.FilePath)
		return
	})

	srv.Listen(":8080")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Client client.IClient
	Server server.IServer

	// Before and After funcs
	BeforeStart []func() error // TODO 处理服务器启动后的事物
	BeforeStop  []func() error
	AfterStart  []func() error
	AfterStop   []func() error
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	Signal  bool
	Debug   bool
}

func (*Config) Init

func (self *Config) Init(opts ...Option)

type IService

type IService interface {
	// The service name
	Name() string
	// Config returns the current options
	Config() *Config
	// Client is used to call services
	Client() client.IClient
	// Server is for handling requests and events
	Server() server.IServer
	// Run the service
	Run() error
	//
	Stop() error
	// The service implementation
	String() string
}

Service is an interface that wraps the lower level libraries within volts. Its a convenience method for building and initialising services.

func New

func New(opts ...Option) IService

NewService creates and returns a new Service based on the packages within.

type Option

type Option func(*Config)

func Client

func Client(cli client.IClient) Option

Client to be used for service

func Debug

func Debug() Option

Client to be used for service under debug mode the port will keep at 35999

func Name

func Name(name string) Option

Name of the service

func Registry

func Registry(r registry.IRegistry) Option

Registry sets the registry for the Server and the underlying components

func Server

func Server(srv server.IServer) Option

Server to be used for service

func Transport

func Transport(t transport.ITransport) Option

Transport sets the transport for the Server and client and the underlying components

Directories

Path Synopsis
memory
Package memory provides a memory broker
Package memory provides a memory broker
demo
handler
internal
acme
Package acme abstracts away various ACME libraries
Package acme abstracts away various ACME libraries
acme/autocert
Package autocert is the ACME provider from golang.org/x/crypto/acme/autocert This provider does not take any config.
Package autocert is the ACME provider from golang.org/x/crypto/acme/autocert This provider does not take any config.
backoff
Package backoff provides backoff functionality
Package backoff provides backoff functionality
buf
metadata
Package metadata is a way of defining message headers
Package metadata is a way of defining message headers
net
pool
Package pool is a connection pool
Package pool is a connection pool
tls
cacher
Package cache provides a registry cache
Package cache provides a registry cache
etcd
Package etcd provides an etcd service registry
Package etcd provides an etcd service registry
Package socket provides a pseudo socket
Package socket provides a pseudo socket

Jump to

Keyboard shortcuts

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