GithubHelp home page GithubHelp logo

xrayinstance's Introduction

XRayInstance

A simple XRay instance code to use xray-core

Requirements

  • GoLang v1.20

How This Code Works

This code loads a JSON configuration file and passes it to InboundHandlerConfig and OutboundHandlerConfig structs using the LoadConfig function.

The ConfigLoader function takes a filename as input and returns a core.Config struct or an error if there was an issue opening or reading the file.

To utilize additional features, you will need to uncomment the imported packages in order to include them in the build.


The main function first calls ShowVersion which prints the version statement of the Xray instance.

Next, it calls ConfigLoader to load the JSON configuration file and create a new Xray instance based on the given configuration. If there is an error, it will log the error and exit.

Then it calls the Start function to start the Xray instance, which includes all registered features. If there is an error, it will log the error and exit.

The Stop function is called to close the Xray instance once the program exits.

Finally, the program will keep running until it receives an os Interrupt or syscall sigterm signal.

During execution, the program explicitly triggers GC to remove garbage from the configuration loading, and also frees up OS memory using debug.FreeOSMemory().


ShowVersion The ShowVersion function prints the version statement of the Xray instance.

Stop The Stop function is used to close the Xray instance.

Start The Start function is used to start the Xray instance. It returns an error if there is an issue starting the instance.

How to run

Simply build the code and run it with your own configuration :

CGO_ENABLED=0 go build -v -ldflags="-s -w" .
XRayInstance config.json

xrayinstance's People

Contributors

sonyacore avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.