gateway

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

Gateway

Package gateway is the main program for TCP and HTTP services.

1 Demo

package main

import (
    "github.com/henrylee2cn/cfgo"
    "github.com/xiaoenai/ants/gateway"
)

func main() {
    cfg := gateway.NewConfig()
    cfgo.MustReg("gateway", cfg)
    // Run a gateway instance with default business logic and default socket protocol.
    gateway.Run(*cfg, nil, nil)
}

2 Usage

2.1 Authorization
  • HTTP short connection gateway

    • Optional authorization
    • Use query parameter access_token to carry authorization token
  • TCP long connection gateway

    • Required authorization
    • Use the first packet of the connection to carry authorization information:
      Package type PULL, URI /auth/verify, BodyType s, Body access token string

Documentation

Overview

Package gateway is the main program for TCP and HTTP services.

Copyright 2018 github.com/xiaoenai. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegBodyCodecForHTTP added in v1.1.0

func RegBodyCodecForHTTP(contentType string, codecId byte)

RegBodyCodecForHTTP registers a mapping of content type to body coder (for http).

func Run

func Run(cfg Config, biz *types.Business, protoFunc socket.ProtoFunc) error

Run the gateway main program. If protoFunc=nil, socket.NewFastProtoFunc is used by default. If biz=nil, types.DefaultBusiness() is used by default.

Types

type Config

type Config struct {
	EnableHttp        bool                     `yaml:"enable_http"`
	EnableSocket      bool                     `yaml:"enable_socket"`
	OuterHttpServer   short.OuterHttpSrvConfig `yaml:"outer_http_server"`
	OuterSocketServer ant.SrvConfig            `yaml:"outer_socket_server"`
	InnerSocketServer ant.SrvConfig            `yaml:"inner_socket_server"`
	InnerSocketClient ant.CliConfig            `yaml:"inner_socket_client"`
	Etcd              etcd.EasyConfig          `yaml:"etcd"`
	Redis             redis.Config             `yaml:"redis"`
}

Config app config

func NewConfig

func NewConfig() *Config

NewConfig creates a default config.

func (*Config) Reload

func (c *Config) Reload(bind cfgo.BindFunc) error

Reload Bi-directionally synchronizes config between YAML file and memory.

Directories

Path Synopsis
samples
Package types is a generated protocol buffer package.
Package types is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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