gateway

package
v6.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: Apache-2.0 Imports: 16 Imported by: 1

README

Gateway

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

Demo

package main

import (
    "github.com/henrylee2cn/cfgo"
    "github.com/xiaoenai/tp-micro/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)
}

Usage

Authorization
  • HTTP short connection gateway

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

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

    • Optional query parameter
    • Use query parameter _seq to carry request ID
  • TCP long connection gateway

    • Required packet seq field
    • The request ID is {session ID}@{packet seq}
HTTP Status Code
  • 200 OK
  • 299 Business error
  • 500 Internal communication error
  • Other codes (200,600)

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 HostsNamespace

func HostsNamespace() string

HostsNamespace returns the gateway hosts prefix of ETCD key.

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, wsProtoFunc tp.ProtoFunc) error

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

func SetHostsNamespace

func SetHostsNamespace(prefix string)

SetHostsNamespace sets the gateway hosts prefix of ETCD key.

func TotalConn

func TotalConn() int32

TotalConn returns the current connections amount.

Types

type Config

type Config struct {
	EnableHttp        bool                `yaml:"enable_http"`
	EnableSocket      bool                `yaml:"enable_socket"`
	EnableWebSocket   bool                `yaml:"enable_web_socket"`
	OuterHttpServer   short.HttpSrvConfig `yaml:"outer_http_server"`
	OuterSocketServer micro.SrvConfig     `yaml:"outer_socket_server"`
	InnerSocketServer micro.SrvConfig     `yaml:"inner_socket_server"`
	InnerSocketClient micro.CliConfig     `yaml:"inner_socket_client"`
	WebSocketServer   micro.SrvConfig     `yaml:"web_socket_server"`
	Etcd              etcd.EasyConfig     `yaml:"etcd"`
}

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
helper
agent/proto
Package agent is a generated protocol buffer package.
Package agent is a generated protocol buffer package.
gray/logic/model
Package model is a generated protocol buffer package.
Package model is a generated protocol buffer package.
gray/types
Package types is a generated protocol buffer package.
Package types is a generated protocol buffer package.
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