<commit_before>// Copyright 2013 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package local

import (
	"fmt"
	"github.com/globocom/config"
	"os/exec"
)

func AddRoute(name, ip string) error {
	domain, err := config.GetString("local:domain")
	if err != nil {
		return err
	}
	routesPath, err := config.GetString("local:routes-path")
	if err != nil {
		return err
	}
	file, _ := filesystem().Open(routesPath + "/" + name)
	defer file.Close()
	template := `server {
	listen 80;
	%s.%s;
	location / {
		proxy_pass http://%s;
	}
}`
	template = fmt.Sprintf(template, name, domain, ip)
	data := []byte(template)
	_, err = file.Write(data)
	return err
}

func RestartRouter() error {
	cmd := exec.Command("sudo", "service", "nginx", "restart")
	return cmd.Run()
}<commit_msg>provision/local: use the proper method for writing<commit_after>// Copyright 2013 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package local

import (
	"fmt"
	"github.com/globocom/config"
	"os/exec"
)

func AddRoute(name, ip string) error {
	domain, err := config.GetString("local:domain")
	if err != nil {
		return err
	}
	routesPath, err := config.GetString("local:routes-path")
	if err != nil {
		return err
	}
	file, _ := filesystem().Create(routesPath + "/" + name)
	defer file.Close()
	template := `server {
	listen 80;
	%s.%s;
	location / {
		proxy_pass http://%s;
	}
}`
	template = fmt.Sprintf(template, name, domain, ip)
	data := []byte(template)
	_, err = file.Write(data)
	return err
}

func RestartRouter() error {
	cmd := exec.Command("sudo", "service", "nginx", "restart")
	return cmd.Run()
}
{'fraction_non_alphanumeric': 0.1518413597733711, 'fraction_numerical': 0.006798866855524079, 'mean_word_length': 3.8251366120218577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3363399', 'n_tokens_mistral': 629, 'n_tokens_neox': 615, 'n_words': 182}