Skip to content

Kadai2 imura81gt #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions kadai1/imura81gt/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM golang:1

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
# this user's GID/UID must match your local user UID/GID to avoid permission issues
# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See
# https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Configure apt, install packages and tools
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& apt-get -y install git iproute2 procps lsb-release \
#
# Install gocode-gomod
&& go get -x -d github.com/stamblerre/gocode 2>&1 \
&& go build -o gocode-gomod github.com/stamblerre/gocode \
&& mv gocode-gomod $GOPATH/bin/ \
#
# Install Go tools
&& go get -u -v \
github.com/mdempsky/gocode \
github.com/uudashr/gopkgs/cmd/gopkgs \
github.com/ramya-rao-a/go-outline \
github.com/acroca/go-symbols \
github.com/godoctor/godoctor \
golang.org/x/tools/cmd/guru \
golang.org/x/tools/cmd/gorename \
github.com/rogpeppe/godef \
github.com/zmb3/gogetdoc \
github.com/haya14busa/goplay/cmd/goplay \
github.com/sqs/goreturns \
github.com/josharian/impl \
github.com/davidrjenni/reftools/cmd/fillstruct \
github.com/fatih/gomodifytags \
github.com/cweill/gotests/... \
golang.org/x/tools/cmd/goimports \
golang.org/x/lint/golint \
golang.org/x/tools/cmd/gopls \
github.com/alecthomas/gometalinter \
honnef.co/go/tools/... \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/mgechev/revive \
github.com/derekparker/delve/cmd/dlv 2>&1 \
#
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
32 changes: 32 additions & 0 deletions kadai1/imura81gt/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/go
{
"name": "Go",
"dockerFile": "Dockerfile",
"runArgs": [
// Uncomment the next line to use a non-root user. On Linux, this will prevent
// new files getting created as root, but you may need to update the USER_UID
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
// "-u", "vscode",

"--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
],

// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"go.gopath": "/go"
},

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "go version",

// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"ms-vscode.go"
]
}
183 changes: 183 additions & 0 deletions kadai1/imura81gt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
Convert Image
================================================================================

TOC
--------------------------------------------------------------------------------
- [Convert Image](#convert-image)
- [TOC](#toc)
- [Q. 【TRY】画像変換コマンドを作ろう](#q-try画像変換コマンドを作ろう)
- [Links](#links)
- [About filepath](#about-filepath)
- [About image](#about-image)
- [Build](#build)
- [Usage](#usage)
- [Test Data](#test-data)
- [Example](#example)
- [e.g. use no option](#eg-use-no-option)
- [e.g. use option](#eg-use-option)

Q. 【TRY】画像変換コマンドを作ろう
--------------------------------------------------------------------------------

次の仕様を満たすコマンドを作って下さい

- [x] 1. ディレクトリを指定する
- [x] 2. 指定したディレクトリ以下のJPGファイルをPNGに変換(デフォルト)
- [x] 3. ディレクトリ以下は再帰的に処理する
- [x] 4. 変換前と変換後の画像形式を指定できる(オプション)

以下を満たすように開発してください

- [x] 5. mainパッケージと分離する
- [x] 6. 自作パッケージと標準パッケージと準標準パッケージのみ使う
- 準標準パッケージ:golang.org/x以下のパッケージ
- [x] 8. ユーザ定義型を作ってみる
- [x] 9. GoDocを生成してみる


Links
--------------------------------------------------------------------------------

### About filepath

- https://golang.org/pkg/path/filepath/

### About image

- [Package image](https://golang.org/pkg/image/)
- [gif](https://golang.org/pkg/image/gif/)
- [jpeg](https://golang.org/pkg/image/jpeg/)
- [png](https://golang.org/pkg/image/png/)
- get format
- [DecodeConfig](https://golang.org/pkg/image/#DecodeConfig)
- [The Go Blog](https://blog.golang.org/)
- [The Go image package](https://blog.golang.org/go-image-package#TOC_5.)


Go doc
--------------------------------------------------------------------------------

```
$ go doc github.com/gopherdojo/dojo7/kadai1/imura81gt/imgconv/img
package img // import "github.com/gopherdojo/dojo7/kadai1/imura81gt/imgconv/img"

func AllImageFiles(dirs []string) (files []string)
func Convert(r io.Reader, w io.Writer, t string) error
func ConvertAll(dirs []string, iType ImageType, oType ImageType) error
func ExpectedImageFiles(files []string, iType ImageType) (f []string)
func IsExpectedImage(path string, iType ImageType) bool
func IsImage(path string) bool
type ImageType struct{ ... }
```

OR

```
cd $(go env GOPATH)/src/github.com/gopherdojo/dojo7/kadai1/imura81gt/imgconv
godoc -http=:8080
```

http://localhost:8080/pkg/github.com/gopherdojo/dojo7/kadai1/imura81gt/imgconv/img/

Build
--------------------------------------------------------------------------------

```
cd $(go env GOPATH)/src/github.com/gopherdojo/dojo7/kadai1/imura81gt/imgconv
GO111MODULE=on go build
```

Usage
--------------------------------------------------------------------------------

```
$ ./imgconv
./imgconv <option> dir1 dir2 dir3
option:
-G convert to gif.
-J convert to jpeg.
-P convert to png.
-g inpt files are gif.
-j inpt files are jpeg.
-p inpt files are png.
```


Test Data
--------------------------------------------------------------------------------

```
$ tree testdata/
testdata/
├── chdir
│ ├── gLenna.gif
│ ├── jLenna.jpeg
│ └── pLenna.png
├── gLenna.gif
├── jLenna.jpg
├── pLenna.png
├── this_is_not_image.gif
├── this_is_not_image.jpg
└── this_is_not_image.png

1 directory, 9 files
$
```


Example
--------------------------------------------------------------------------------

### e.g. use no option

```
$ ./imgconv testdata/
```

In stdout, the command output input files and output files.

```
["testdata/chdir/jLenna.jpeg" "testdata/jLenna.jpg"]
["output/png/testdata/chdir/jLenna.png" "output/png/testdata/jLenna.png"]
```

```
$ tree output/
output/
└── png
└── testdata
├── chdir
│ └── jLenna.png
└── jLenna.png
$
```

### e.g. use option

- input: png, jpeg
- output: gif

```
$ ./imgconv testdata/ -p -j -G
```

In stdout, the command output input files and output files.

```

["testdata/chdir/jLenna.jpeg" "testdata/chdir/pLenna.png" "testdata/jLenna.jpg" "testdata/pLenna.png"]
["output/gif/testdata/chdir/jLenna.gif" "output/gif/testdata/chdir/pLenna.gif" "output/gif/testdata/jLenna.gif" "output/gif/testdata/pLenna.gif"]
```

```
$ tree output/
output/
└── gif
└── testdata
├── chdir
│ ├── jLenna.gif
│ └── pLenna.gif
├── jLenna.gif
└── pLenna.gif
$
```
2 changes: 2 additions & 0 deletions kadai1/imura81gt/imgconv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output
imgconv
3 changes: 3 additions & 0 deletions kadai1/imura81gt/imgconv/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/gopherdojo/dojo7/kadai1/imura81gt/imgconv

go 1.12
1 change: 1 addition & 0 deletions kadai1/imura81gt/imgconv/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/gopherdojo/dojo7 v0.0.0-20190903074013-69385d40c994 h1:UbdhtSFDdFiSYOb/TkEmlRIUFQRrBlKOzVDY3+SXaSw=
Loading