Skip to content

Commit

Permalink
move error generator to common
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Dec 3, 2017
1 parent 5e27e3d commit d43a23a
Show file tree
Hide file tree
Showing 38 changed files with 84 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package app

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg app -path App
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg app -path App
2 changes: 1 addition & 1 deletion app/dispatcher/impl/default.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package impl

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg impl -path App,Dispatcher,Default
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg impl -path App,Dispatcher,Default

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/dns/dns.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dns

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg dns -path App,DNS
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg dns -path App,DNS

import (
"net"
Expand Down
2 changes: 1 addition & 1 deletion app/dns/server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package server

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg server -path App,DNS,Server
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg server -path App,DNS,Server

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/log/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package log

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg log -path App,Log
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg log -path App,Log

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/inbound/inbound.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package inbound

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg inbound -path App,Proxyman,Inbound
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg inbound -path App,Proxyman,Inbound

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/mux/mux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mux

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg mux -path App,Proxyman,Mux
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg mux -path App,Proxyman,Mux

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/outbound/outbound.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package outbound

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg outbound -path App,Proxyman,Outbound
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg outbound -path App,Proxyman,Outbound

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/proxyman.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package proxyman defines applications for manageing inbound and outbound proxies.
package proxyman

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg proxyman -path App,Proxyman
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg proxyman -path App,Proxyman

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/router/router.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package router

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg router -path App,Router
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg router -path App,Router

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion common/buf/buf.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package buf

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg buf -path Buf
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg buf -path Buf
2 changes: 1 addition & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See each sub-package for detail.
package common

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg common -path Common
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg common -path Common

// Must panics if err is not nil.
func Must(err error) {
Expand Down
2 changes: 1 addition & 1 deletion common/crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package crypto provides common crypto libraries for V2Ray.
package crypto

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg crypto -path Crypto
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg crypto -path Crypto
47 changes: 47 additions & 0 deletions common/errors/errorgen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"strings"

"v2ray.com/core/common"
)

var (
pkg = flag.String("pkg", "", "Target package")
path = flag.String("path", "", "Path")
)

func main() {
flag.Parse()

if len(*pkg) == 0 {
panic("Package is not specified.")
}

if len(*path) == 0 {
panic("Path is not specified.")
}

paths := strings.Split(*path, ",")
for i := range paths {
paths[i] = "\"" + paths[i] + "\""
}
pathStr := strings.Join(paths, ", ")

file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("Failed to generate errors.generated.go: %v", err)
}

common.Must2(fmt.Fprintln(file, "package", *pkg))
common.Must2(fmt.Fprintln(file, ""))
common.Must2(fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\""))
common.Must2(fmt.Fprintln(file, ""))
common.Must2(fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("+pathStr+") }"))

common.Must(file.Close())
}
2 changes: 1 addition & 1 deletion common/net/net.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package net is a drop-in replacement to Golang's net package, with some more functionalities.
package net

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg net -path Net
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg net -path Net
2 changes: 1 addition & 1 deletion common/protocol/protocol.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package protocol

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg protocol -path Protocol
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg protocol -path Protocol
2 changes: 1 addition & 1 deletion common/retry/retry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package retry

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg retry -path Retry
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg retry -path Retry

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// connections.
package core

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg core -path Core
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg core -path Core

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion main/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg main -path Main
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg main -path Main

import (
"flag"
Expand Down
2 changes: 1 addition & 1 deletion proxy/blackhole/blackhole.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package blackhole is an outbound handler that blocks all connections.
package blackhole

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg blackhole -path Proxy,Blackhole
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg blackhole -path Proxy,Blackhole

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion proxy/dokodemo/dokodemo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dokodemo

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg dokodemo -path Proxy,Dokodemo
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg dokodemo -path Proxy,Dokodemo

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion proxy/freedom/freedom.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package freedom

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg freedom -path Proxy,Freedom
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg freedom -path Proxy,Freedom

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion proxy/http/http.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package http

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg http -path Proxy,HTTP
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg http -path Proxy,HTTP
2 changes: 1 addition & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 2. Register a config creator through common.RegisterConfig.
package proxy

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg proxy -path Proxy
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg proxy -path Proxy

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion proxy/shadowsocks/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
// R.I.P Shadowsocks
package shadowsocks

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg shadowsocks -path Proxy,Shadowsocks
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg shadowsocks -path Proxy,Shadowsocks
2 changes: 1 addition & 1 deletion proxy/socks/socks.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package socks provides implements of Socks protocol 4, 4a and 5.
package socks

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg socks -path Proxy,Socks
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg socks -path Proxy,Socks
2 changes: 1 addition & 1 deletion proxy/vmess/encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package encoding

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg encoding -path Proxy,VMess,Encoding
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg encoding -path Proxy,VMess,Encoding
2 changes: 1 addition & 1 deletion proxy/vmess/inbound/inbound.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package inbound

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg inbound -path Proxy,VMess,Inbound
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg inbound -path Proxy,VMess,Inbound

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion proxy/vmess/outbound/outbound.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package outbound

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg outbound -path Proxy,VMess,Outbound
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg outbound -path Proxy,VMess,Outbound

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion proxy/vmess/vmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// clients with 'socks' for proxying.
package vmess

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg vmess -path Proxy,VMess
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg vmess -path Proxy,VMess

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/headers/http/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package http

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg http -path Transport,Internet,Headers,HTTP
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg http -path Transport,Internet,Headers,HTTP

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/internet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package internet

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg internet -path Transport,Internet
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg internet -path Transport,Internet
2 changes: 1 addition & 1 deletion transport/internet/kcp/kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// xtaci@github for translating to Golang
package kcp

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg kcp -path Transport,Internet,mKCP
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg kcp -path Transport,Internet,mKCP
2 changes: 1 addition & 1 deletion transport/internet/tcp/tcp.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package tcp

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg tcp -path Transport,Internet,TCP
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg tcp -path Transport,Internet,TCP
2 changes: 1 addition & 1 deletion transport/internet/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"v2ray.com/core/common/buf"
)

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg tls -path Transport,Internet,TLS
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg tls -path Transport,Internet,TLS

var (
_ buf.Writer = (*conn)(nil)
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/udp/udp.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package udp

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg udp -path Transport,Internet,UDP
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg udp -path Transport,Internet,UDP
2 changes: 1 addition & 1 deletion transport/internet/websocket/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Websocket transport implements a HTTP(S) compliable, surveillance proof transpor
*/
package websocket

//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg websocket -path Transport,Internet,WebSocket
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg websocket -path Transport,Internet,WebSocket
2 changes: 1 addition & 1 deletion v2ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func newSimpleServer(config *Config) (*simpleServer, error) {
if p := policy.FromSpace(space); p == nil {
p, err := app.CreateAppFromConfig(ctx, &policy.Config{
Level: map[uint32]*policy.Policy{
1: &policy.Policy{
1: {
Timeout: &policy.Policy_Timeout{
ConnectionIdle: &policy.Second{
Value: 600,
Expand Down

0 comments on commit d43a23a

Please sign in to comment.