generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from moul/dev/moul/poc
feat: POC
- Loading branch information
Showing
7 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module moul.io/guilhunize | ||
|
||
go 1.13 | ||
|
||
require gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717 h1:OvXt/p4cdwNl+mwcWMq/AxaKFkhdxcjx+tx+qf4EOvY= | ||
gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717/go.mod h1:cKXr3E0k4aosgycml1b5z33BVV6hai1Kh7uDgFOkbcs= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package guilhunize // import "moul.io/guilhunize" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package guilhunize | ||
|
||
import "strings" | ||
|
||
var mapping = [][2]string{ | ||
{"refactors", "refractos"}, | ||
{"refactos", "refractos"}, | ||
{"refactoré", "refractoré"}, | ||
{"refactor", "refracto"}, | ||
{"refacto", "refracto"}, | ||
{"scaleway", "scalaway"}, | ||
{"interface", "i-love-interface"}, | ||
{"déchiffrement", "désenchiffrement"}, | ||
{" chiffrement", " cryptage"}, | ||
} | ||
|
||
func Guilhunize(input string) string { | ||
// FIXME: refactor to use words instead of regexps | ||
input = strings.ToLower(input) | ||
for _, pair := range mapping { | ||
input = strings.Replace(input, pair[0], pair[1], -1) | ||
} | ||
return input | ||
} | ||
|
||
// FIXME: implement "Unguilhunize" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package guilhunize | ||
|
||
import "fmt" | ||
|
||
func ExampleGuilhunize() { | ||
fmt.Println(Guilhunize("salut, j'aime bien faire des interfaces dans les refactors, surtout lorsqu'il faut faire du chiffrement ou du déchiffrement.")) | ||
// Output: salut, j'aime bien faire des i-love-interfaces dans les refractos, surtout lorsqu'il faut faire du cryptage ou du désenchiffrement. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,34 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
cli "gopkg.in/urfave/cli.v2" | ||
"moul.io/guilhunize/guilhunize" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Hello World!") | ||
app := cli.App{Action: run} | ||
if err := app.Run(os.Args); err != nil { | ||
log.Printf("error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run(c *cli.Context) error { | ||
message := strings.Join(c.Args().Slice(), " ") | ||
if message == "" { | ||
in, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
return err | ||
} | ||
message = string(in) | ||
} | ||
out := guilhunize.Guilhunize(message) | ||
fmt.Println(out) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package main | ||
|
||
import "os" | ||
|
||
func Example() { | ||
os.Args = []string{"", "salut, j'aime bien faire des interfaces dans les refactors, surtout lorsqu'il faut faire du chiffrement ou du déchiffrement."} | ||
main() | ||
// Output: Hello World! | ||
// Output: salut, j'aime bien faire des i-love-interfaces dans les refractos, surtout lorsqu'il faut faire du cryptage ou du désenchiffrement. | ||
} |