Go example
Overview
This example will help you integrate ONLYOFFICE Docs into your web application written in Go.
It is intended for testing purposes and demonstrating functionality of the editors. DO NOT use this integration example on your own server without proper code modifications. In case you enabled the test example, disable it before going for production.
Important security info
Please keep in mind the following security aspects when you are using test examples:
- There is no protection of the storage from unauthorized access since there is no need for authorization.
- There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
- There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Docs.
- There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Docs from another domain.
Step 1. Install ONLYOFFICE Docs
Download and install ONLYOFFICE Docs (packaged as Document Server).
See the detailed guide to learn how to install Document Server for Windows.
Step 2. Download the Go code for the editors integration
Download the Go example from our site.
To connect the editors to your website, specify the path to the editors installation, server protocol, address and port in the configuration.env file:
SERVER_ADDRESS=http(s)://address (optional)
SERVER_PORT=port
DOC_SERVER_HOST=http://documentserver/
JWT_IS_ENABLED=flag
JWT_SECRET=secret
JWT_HEADER=Authorization
where the documentserver is the name of the server with the ONLYOFFICE Docs installed. address is the address of the server, port is the server port.
If you want to experiment with the editor configuration, modify the parameters in the templates/editor.html file.
Step 3. Install the prerequisites
To run the Go example code, install the Go compiler:
- Go (download from the Go lang website)
Step 4. Set environment variables
Having installed the compiler, update the Golang environment variables:
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin
Step 5. Configure JWT
Open the config/configuration.json file and enable JWT:
{
"JWT_IS_ENABLED" : true,
}
Also, specify the same secret key as used in your ONLYOFFICE Docs:
{
"JWT_SECRET" : "secret",
}
Step 6. Start the application
-
Go to the project root.
-
Run:
go run main.go
-
In your browser go to server.address and server.port.
Step 7. Check accessibility
In case the example and ONLYOFFICE Docs are installed on different computers, make sure that your server with the example installed has access to the ONLYOFFICE Docs with the address which you specify instead of documentserver in the configuration files.