ラベル beego の投稿を表示しています。 すべての投稿を表示
ラベル beego の投稿を表示しています。 すべての投稿を表示

2019年10月4日金曜日

beegoのローカル開発環境でsslを使う方法

自己証明書を作成

  • プライベートキーを作成
$ openssl genrsa -out private_key 2048
Generating RSA private key, 2048 bit long modulus
...........................................+++
...........................+++
e is 65537 (0x10001)
  • パブリックキーを作成
$ openssl req -new -x509 -key private_key -out public_key -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) []:jp
State or Province Name (full name) []:tokyo
Locality Name (eg, city) []:tokyo
Organization Name (eg, company) []:dmm.com
Organizational Unit Name (eg, section) []:dmm.com
Common Name (eg, fully qualified host name) []:test.dmm.com
Email Address []:test@dmm.com

sslを有効にするため、設定ファイル(app.con)に情報を追加

設定ファイル(./conf/app.conf)に、以下の情報を追加します。
EnableHTTPS = true
HTTPSPort = 443
HTTPSCertFile = "./local_cert/public_key" # 前のステップで作ったパブリックキーのファイルのフルパスを入れる。 自分の場合は「プロジェクトのパス/local_cert/」の直下に置いたのでそのような設定
HTTPSKeyFile = "./local_cert/private_key" # 前のステップで作ったプライベートキーのファイルのフルパスを入れる

beeコマンドで再起動

bee runコマンドで再起動します。以下のような情報が表示されるはずです。
$ bee run
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v1.10.0
2019/10/03 15:41:27 INFO     ▶ 0001 Using 'example-web' as 'appname'
2019/10/03 15:41:27 INFO     ▶ 0002 Initializing watcher...
2019/10/03 15:41:34 SUCCESS ▶ 0003 Built Successfully!
2019/10/03 15:41:34 INFO     ▶ 0004 Restarting 'magazine-front'...
2019/10/03 15:41:34 SUCCESS ▶ 0005 './magazine-front' is running...
2019/10/03 15:41:34.828 [I] [asm_amd64.s:1337]  http server Running on http://:8080
2019/10/03 15:41:34.829 [I] [asm_amd64.s:1337]  https server Running on https://:443
2019/10/03 15:42:06.284 [server.go:3010]  [HTTP] http: TLS handshake error from 127.0.0.1:56856: remote error: tls: unknown certificate
2019/10/03 15:42:09.062 [server.go:3010]  [HTTP] http: TLS handshake error from 127.0.0.1:56881: remote error: tls: unknown certificate

ブラウザーでsslページの動作を確認

最後ブラウザーに「https://127.0.0.1」を入れて、動作を確認します。「この接続ではプライバシーが保護されません...」が表示されたら、「詳細設定」/「127.0.0.1 にアクセスする(安全ではありません)」の順に進めます。

2019年4月19日金曜日

Macでgo言語のウェブアプリケーション開発環境のインストール及び設定

1. まず、インストール(Homebrewがインストール済みを前提にします)


$ brew install go
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
.
.(略)
.
==> Deleted Formulae
safe
==> Downloading https://homebrew.bintray.com/bottles/go-1.12.4.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/99/9920e9264e80f0bac5098a0bbdbd1818c2c44eba37d3b9accd61c1236fcad5f2?__gda__=exp=1555645429~hmac=e139494e5eae781
######################################################################## 100.0%
==> Pouring go-1.12.4.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/go/1.12.4: 9,798 files, 452.6MB

2. 癖のようでバージョンを確認する


$ go version
go version go1.12.4 darwin/amd64

3. $GOPATHの設定


echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bash_profile
source ~/.bash_profile

4. beegoをインストール


$go get -u github.com/astaxie/beego
$go get -u github.com/beego/bee
※ 普通に行けると思ったが、以下のエラーができました。gitがないと怒られました。
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/astaxie/beego: exec: "git": executable file not found in $PATH
gitをインストールします。→gitのインストール方法を略します。
無事にgitをインストールできたら、再度上記のbeegoインストールコマンドを実行します。今度無事に実行できたようです。
上記実効後、以下のようなフォルダが作成されたら、ダウンロードできた証拠です。
ls  ~/go/src/github.com/
astaxie/  beego/  shiena/

5. プロジェクトを作成


※今回のプロジェクト名は[test-web]とした場合
$ bee new test-web
上記実行すると、[~/go/src/]の配下に[test-web]というプロジェクトが作られたはずです。

6. プロジェクトを実行


作られたプロジェクトの配下に移動した後、[bee run]を実行します。
cd ~/go/src/test-web/
~/go/src/test-web
$ bee run
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v1.10.0
2019/04/19 14:08:12 INFO     ▶ 0001 Using 'test-web' as 'appname'
2019/04/19 14:08:12 INFO     ▶ 0002 Initializing watcher...
test-web/controllers
test-web/routers
test-web
2019/04/19 14:08:16 SUCCESS  ▶ 0003 Built Successfully!
2019/04/19 14:08:16 INFO     ▶ 0004 Restarting 'test-web'...
2019/04/19 14:08:16 SUCCESS  ▶ 0005 './test-web' is running...
2019/04/19 14:08:19.753 [I] [asm_amd64.s:1337]  http server Running on http://:8080

7. ブラウザーで確認


ブラウザーのアドレスに[http://localhost:8080/] を入力、以下のように表示されるはずです。