v0.17.19 Latest Latest

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

Go to latest
Published: Apr 6, 2022 License: Apache-2.0 Imports: 64 Imported by: 0



nolint: errcheck

Package serv provides an API to include and use the GraphJin service with your own code. For detailed documentation visit

Example usage:

package main

import (
	_ ""

func main() {
	conf := serv.Config{ AppName: "Test App" }
	conf.DB.Host := ""
	conf.DB.Port := 5432
	conf.DB.DBName := "test_db"
	conf.DB.User := "postgres"
	conf.DB.Password := "postgres"

	gjs, err := serv.NewGraphJinService(conf)
	if err != nil {

 	if err := gjs.Start(); err != nil {



This section is empty.


This section is empty.


func GetConfigName

func GetConfigName() string

func InitAdmin

func InitAdmin(db *sql.DB, dbtype string) error

func NewDB

func NewDB(conf *Config, openDB bool, log *zap.SugaredLogger, fs afero.Fs) (*sql.DB, error)


type Action

type Action struct {
	Name     string
	SQL      string
	AuthName string `mapstructure:"auth_name"`

Action struct contains config values for a GraphJin service action

type Admin

type Admin struct {
	// HotDeploy enables the ability to hot-deploy a new configuration
	// to GraphJin.
	HotDeploy bool `mapstructure:"hot_deploy"`

	// AdminSecret is the secret key used to control access
	// to the admin api
	AdminSecretKey string `mapstructure:"admin_secret_key"`

Admin struct contains config values used for adminstration of the GraphJin service

type Auth

type Auth = auth.Auth

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
	Date    string

func GetBuildInfo

func GetBuildInfo() BuildInfo

type Config

type Config struct {

	// Core holds config values for the GraphJin compiler
	Core `mapstructure:",squash"`

	// Serv holds config values for the GraphJin Service
	Serv `mapstructure:",squash"`

	// Admin holds config values for adminstrationof GraphJin Service
	Admin `mapstructure:",squash"`
	// contains filtered or unexported fields

Config struct holds the GraphJin service config values

func NewConfig

func NewConfig(config, format string) (*Config, error)

func ReadInConfig

func ReadInConfig(configFile string) (*Config, error)

ReadInConfig function reads in the config file for the environment specified in the GO_ENV environment variable. This is the best way to create a new GraphJin config.

func ReadInConfigFS

func ReadInConfigFS(configFile string, fs afero.Fs) (*Config, error)

ReadInConfigFS is the same as ReadInConfig but it also takes a filesytem as an argument

func (*Config) RelPath

func (c *Config) RelPath(p string) string

func (*Config) SetHash

func (c *Config) SetHash(hash string)

func (*Config) SetName

func (c *Config) SetName(name string)

type Core

type Core = core.Config

type Database

type Database struct {
	Type            string
	Host            string
	Port            uint16
	DBName          string
	User            string
	Password        string
	Schema          string
	PoolSize        int           `mapstructure:"pool_size"`
	MaxConnections  int           `mapstructure:"max_connections"`
	MaxConnIdleTime time.Duration `mapstructure:"max_connection_idle_time"`
	MaxConnLifeTime time.Duration `mapstructure:"max_connection_life_time"`
	PingTimeout     time.Duration `mapstructure:"ping_timeout"`
	EnableTLS       bool          `mapstructure:"enable_tls"`
	ServerName      string        `mapstructure:"server_name"`
	ServerCert      string        `mapstructure:"server_cert"`
	ClientCert      string        `mapstructure:"client_cert"`
	ClientKey       string        `mapstructure:"client_key"`

Database config

type JWTConfig

type JWTConfig = auth.JWTConfig

type Option

type Option func(*service) error

func OptionDeployActive

func OptionDeployActive() Option

func OptionSetFS

func OptionSetFS(fs afero.Fs) Option

type Payload

type Payload struct {
	Data   json.RawMessage `json:"data,omitempty"`
	Errors []core.Error    `json:"errors,omitempty"`

type RateLimiter

type RateLimiter struct {
	Rate     float64
	Bucket   int
	IPHeader string `mapstructure:"ip_header"`

RateLimiter sets the API rate limits

type Serv

type Serv struct {
	// AppName is the name of your application used in log and debug messages
	AppName string `mapstructure:"app_name"`

	// Production when set to true runs the service with production level
	// security and other defaults. For example allow lists are enforced.
	Production bool

	// ConfigPath is the default path to find all configuration
	// files and scripts under
	ConfigPath string `mapstructure:"config_path"`

	// SecretsFile is the file for the secret key store
	SecretsFile string `mapstructure:"secrets_file"`

	// LogLevel can be debug, error, warn, info
	LogLevel string `mapstructure:"log_level"`

	// LogFormat can be json or simple
	LogFormat string `mapstructure:"log_format"`

	// HostPost to run the service on. Example localhost:8080
	HostPort string `mapstructure:"host_port"`

	// Host to run the service on
	Host string

	// Port to run the service on
	Port string

	// HTTPGZip enables HTTP compression
	HTTPGZip bool `mapstructure:"http_compress"`

	// ServerTiming enables the Server-Timing header
	ServerTiming bool `mapstructure:"server_timing"`

	// Enable the web UI. Disabled in production
	WebUI bool `mapstructure:"web_ui"`

	// EnableTracing enables OpenTrace request tracing
	EnableTracing bool `mapstructure:"enable_tracing"`

	// WatchAndReload enables reloading the service on config changes
	WatchAndReload bool `mapstructure:"reload_on_config_change"`

	// AuthFailBlock when enabled blocks requests with a 401 on auth failure
	AuthFailBlock bool `mapstructure:"auth_fail_block"`

	// MigrationsPath is the path to the database migration files
	MigrationsPath string `mapstructure:"migrations_path"`

	// AllowedOrigins sets the HTTP CORS Access-Control-Allow-Origin header
	AllowedOrigins []string `mapstructure:"cors_allowed_origins"`

	// AllowedHeaders sets the HTTP CORS Access-Control-Allow-Headers header
	AllowedHeaders []string `mapstructure:"cors_allowed_headers"`

	// DebugCORS enables debug logs for cors
	DebugCORS bool `mapstructure:"cors_debug"`

	// CacheControl sets the HTTP Cache-Control header
	CacheControl string `mapstructure:"cache_control"`

	// Telemetry struct contains OpenCensus metrics and tracing related config
	Telemetry Telemetry

	// Auth set the default auth used by the service
	Auth Auth

	// Auths sets multiple auths to be used by actions
	Auths []Auth

	// DB struct contains db config
	DB Database `mapstructure:"database"`

	Actions []Action

	// RateLimiter sets the API rate limits
	RateLimiter RateLimiter `mapstructure:"rate_limiter"`

Serv struct contains config values used by the GraphJin service

type Service

type Service struct {
	// contains filtered or unexported fields

func NewGraphJinService

func NewGraphJinService(conf *Config, options ...Option) (*Service, error)

func (*Service) Attach

func (s *Service) Attach(mux *http.ServeMux) error

func (*Service) Deploy

func (s *Service) Deploy(conf *Config, options ...Option) error

func (*Service) GetDB

func (s *Service) GetDB() *sql.DB

func (*Service) GraphQL

func (s *Service) GraphQL(c context.Context,
	query string,
	vars json.RawMessage,
	rc *core.ReqConfig) (*core.Result, error)

func (*Service) Start

func (s *Service) Start() error

func (*Service) Subscribe

func (s *Service) Subscribe(
	c context.Context,
	query string,
	vars json.RawMessage,
	rc *core.ReqConfig) (*core.Member, error)

type Telemetry

type Telemetry struct {
	// Debug enables debug logging for metrics and tracing data.
	Debug bool

	// Interval to send out metrics and tracing data
	Interval *time.Duration

	Metrics struct {
		// Exporter is the name of the metrics exporter to use. Example: prometheus
		Exporter string

		// Endpoint to send the data to.
		Endpoint string

		// Namespace is set based on your exporter configration
		Namespace string

		// Key is set based on your exporter configuration
		Key string

	Tracing struct {
		// Exporter is the name of the tracing exporter to use. Example: zipkin
		Exporter string

		// Endpoint to send the data to. Example: http://zipkin:9411/api/v2/spans
		Endpoint string

		// Sample sets how many requests to sample for tracing: Example: 0.6
		Sample string

		// IncludeQuery when set the GraphQL query is included in the tracing data
		IncludeQuery bool `mapstructure:"include_query"`

		// IncludeParams when set variables used with the query are included in the
		// tracing data
		IncludeParams bool `mapstructure:"include_params"`

		// ExcludeHealthCheck when set health check tracing is excluded from the
		// tracing data
		ExcludeHealthCheck bool `mapstructure:"exclude_health_check"`

Telemetry struct contains OpenCensus metrics and tracing related config


Path Synopsis

Jump to

Keyboard shortcuts

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