1. 무료쇼핑몰 QOR 

  - QOR은 비즈니스 애플리케이션, CMS 및 전자 상거래 시스템에 필요한 공통 기능을 추상화 한 Go로 작성된 라이브러리

   세트입니다. 원래 QOR은 Ruby on Rails로 만들어졌으나 Go언어로 재작성 된 CMS 쇼핑몰 오픈소스입니다.

  - example 사이트 : https://github.com/qor/qor-example

  

2. 설치순서

  - 사이트에 나와있는 설치순서대로 하면 되지만 정상적으로 돌아가게 하기 위해

    몇가지 추가적인 수정이 필요하여 그 경험을 공유합니다.

# go get으로 github에서 소스를 받는다. (git 설치 안되어있으면 yum install git 으로)

#아래 명령어를 실행하면 앞 게시물(https://dodo-it.tistory.com/65)에서 go 설치시 지정한 go_work 하위에 다운로드됨. 

$ go get -u github.com/qor/qor-example


# mariadb를 설치(https://dodo-it.tistory.com/7)하고 아래와 같이 접속(root계정으로)하여 

# qor_example 데이터베이스를 만든다. (mariadb 설치시 root의 접속비밀번호는 1로 설정함)

$ mysql -uroot -p

mysql> CREATE DATABASE qor_example;


# DB 설정 및 프로그램 수정

#1) DB 연결설정

#2) 프로그램수정 (원본예제대로 하면 로긴안되고 제품리스트에서 제품 클릭하면 상세페이지로 넘어가지 않는다.)

#==> 아래에 추가적으로 설명한것을 참고로 수정한다.


#샘플데이터를 DB에 생성한다.

#생성시 SSL오류가 발생하면 /etc/yum.conf 을 vi에디터로 열고 sslverify=false 로 설정한다.

$ go run config/db/seeds/main.go config/db/seeds/seeds.go


# qor-example 경로로 이동 후 서버를 구동시켜본다.

# 참고로 윈도우에서 경로이동시에는 cd %GOPATH%/src/github.com/qor/qor-example 를 사용한다.

$ cd $GOPATH/src/github.com/qor/qor-example

$ go run main.go



3. DB 설정 및 프로그램 수정

  1) DB설정

    - /usr/local/go_work/src/github.com/qor/qor-example/config 하위에 보면 샘플설정파일이 몇개 있다.

     그중에 샘플데이터 생성을 위해 database.example.yml 파일을 database.yml 로 복사 후 내부에 패스워드를 설정한다.

#경로이동

$ cd $GOPATH/src/github.com/qor/qor-example/config


#파일 복사 후 rename

$ mv database.example.yml database.yml

 

#database.yml 파일 수정 ==> password: 1 을 아래에 추가함.(패스워드는 mariadb root 패스워드 설정시 1로 설정함)

$ vi database.yml 

------------------------------------------------------------

db:

  adapter: mysql

  name: qor_example

  user: root

  password: 1          

-----------------------------------------------------------

# 저장 후 빠져나오기 ==> esc클릭-> ':' 입력 후 --> wq 입력



  2) 프로그램수정

    a) 로긴안되는 문제 수정

      ==> /usr/local/go_work/src/github.com/qor/auth/providers/password/handlers.go 파일 수정

package password


import (

"reflect"

"strings"


"github.com/qor/auth"

"github.com/qor/auth/auth_identity"

"github.com/qor/auth/claims"

"github.com/qor/qor/utils"

"github.com/qor/session"

)


// DefaultAuthorizeHandler default authorize handler

var DefaultAuthorizeHandler = func(context *auth.Context) (*claims.Claims, error) {

var (

                //authInfo    auth_identity.Basic <== 기존소스 Basic을 AuthIdentity 로 수정             

authInfo    auth_identity.AuthIdentity               

req         = context.Request

tx          = context.Auth.GetDB(req)

provider, _ = context.Provider.(*Provider)

)


req.ParseForm()

authInfo.Provider = provider.GetName()

authInfo.UID = strings.TrimSpace(req.Form.Get("login"))


if tx.Model(context.Auth.AuthIdentityModel).Where(authInfo).Scan(&authInfo).RecordNotFound() {

return nil, auth.ErrInvalidAccount

}


if provider.Config.Confirmable && authInfo.ConfirmedAt == nil {

currentUser, _ := context.Auth.UserStorer.Get(authInfo.ToClaims(), context)

provider.Config.ConfirmMailer(authInfo.UID, context, authInfo.ToClaims(), currentUser)


return nil, ErrUnconfirmed

}


if err := provider.Encryptor.Compare(authInfo.EncryptedPassword, strings.TrimSpace(req.Form.Get("password"))); err == nil {

return authInfo.ToClaims(), err

}


return nil, auth.ErrInvalidPassword

}


// DefaultRegisterHandler default register handler

var DefaultRegisterHandler = func(context *auth.Context) (*claims.Claims, error) {

var (

err         error

currentUser interface{}

schema      auth.Schema

//authInfo    auth_identity.Basic <== 기존소스 Basic을 AuthIdentity 로 수정             

authInfo    auth_identity.AuthIdentity       

req         = context.Request

tx          = context.Auth.GetDB(req)

provider, _ = context.Provider.(*Provider)

)


req.ParseForm()

if req.Form.Get("login") == "" {

return nil, auth.ErrInvalidAccount

}


if req.Form.Get("password") == "" {

return nil, auth.ErrInvalidPassword

}


authInfo.Provider = provider.GetName()

authInfo.UID = strings.TrimSpace(req.Form.Get("login"))


if !tx.Model(context.Auth.AuthIdentityModel).Where(authInfo).Scan(&authInfo).RecordNotFound() {

return nil, auth.ErrInvalidAccount

}


if authInfo.EncryptedPassword, err = provider.Encryptor.Digest(strings.TrimSpace(req.Form.Get("password"))); err == nil {

schema.Provider = authInfo.Provider

schema.UID = authInfo.UID

schema.Email = authInfo.UID

schema.RawInfo = req


currentUser, authInfo.UserID, err = context.Auth.UserStorer.Save(&schema, context)

if err != nil {

return nil, err

}


// create auth identity

authIdentity := reflect.New(utils.ModelType(context.Auth.Config.AuthIdentityModel)).Interface()

if err = tx.Where(authInfo).FirstOrCreate(authIdentity).Error; err == nil {

if provider.Config.Confirmable {

context.SessionStorer.Flash(context.Writer, req, session.Message{Message: ConfirmFlashMessage, Type: "success"})

err = provider.Config.ConfirmMailer(schema.Email, context, authInfo.ToClaims(), currentUser)

}


return authInfo.ToClaims(), err

}

}


return nil, err

}



   b) 제품리스트에서 제품 클릭하면 상세페이지로 넘어가지 않는 문제 수정

      ==> /usr/local/go_work/src/github.com/qor/qor-example/app/products/views/gender.tmpl 수정

<main class="container product_index">


<div class="grid">

  <div class="grid__col is-2 product_options">

    <h2>CATEGORIES</h2>

    <ul>

      {{ range $category := get_categories }}

        <li><a href="{{ $category.DefaultPath }}">{{$category.Name}}</a></li>

      {{ end }}

    </ul>


    <h2>COLORS</h2>

    <ul class="product_options-color">

      <li><a rel="nofollow" href="#"><span style="background:#eae3d3"></span>Beige</a></li>

      <li><a rel="nofollow" href="#"><span style="background:#222"></span>Black</a></li>

      <li><a rel="nofollow" href="#"><span style="background:#f79858"></span>Blue</a></li>

      <li><a rel="nofollow" href="#"><span style="background:#f56060"></span>Brown</a></li>

      <li><a rel="nofollow" href="#"><span style="background:#44c28d"></span>Green</a></li>

      <li><a rel="nofollow" href=""><span style="background:#999"></span>Grey</a></li>

      <li><a rel="nofollow" href=""><span style="background:#f79858"></span>Orange</a></li>

      <li><a rel="nofollow" href=""><span style="background:#b27ef8"></span>Purple</a></li>

      <li><a rel="nofollow" href=""><span style="background:#f56060"></span>Red</a></li>

      <li><a rel="nofollow" href=""><span style="background:#fff;border: 1px solid #e8e9eb;width:13px;height:13px;"></span>White</a></li>

    </ul>


    <h2>SIZES</h2>

    <ul class="product_options-size">

      <li><a rel="nofollow" href="#">XS</a></li>

      <li><a rel="nofollow" href="#">S</a></li>

      <li><a rel="nofollow" href="#">M</a></li>

      <li><a rel="nofollow" href="#">L</a></li>

      <li><a rel="nofollow" href="#">XL</a></li>

      <li><a rel="nofollow" href="#">XXL</a></li>

    </ul>

  </div>


  <div class="grid__col is-10 product_lists">

    <h1>ALL PRODUCTS (8)</h1>

    <ul class="grid">

      {{range .Products}}

        <li class="grid__col is-3">

          <!--<a href="{{.DefaultPath}}"> ==> 이미지클릭시 상세링크 부분으로 계속 초기페이지로 간다.  -->

          <a href="{{.DefaultPath}}products/{{.Code}}"> <!-- ==> 정확한 상세페이지 URL이 되도록 수정한다. -->

            <div class="product_image" style="background-image: url({{.MainImageURL}});">

              <div class="image_overlay"></div>

              <div class="add_to_cart">Add to cart</div>

              <div class="stats">

                <div class="stats-container">

                  <span class="product_price">${{.Price}}</span>

                  <span class="product_name">{{.Name}}</span>


                  <div class="product_meta">

                    <strong>SIZES</strong>

                    <span>

                      XS, S, M, L, XL, XXL

                    </span>

                    <strong>COLORS</strong>

                    <div class="colors">

                      <span style="background:#f79858"></span>

                      <span style="background:#f56060"></span>

                      <span style="background:#44c28d"></span>

                      <span style="background:#f79858"></span>

                    </div>

                  </div>

                </div>

              </div>

            </div>

          </a>

        </li>

      {{end}}

    </ul>

  </div>

</div>

</main>

 


4. 실행화면

  1) 사용자 접속 URL : http://localhost:7000






  2) 관리자 접속 URL : http://localhost:7000/admin




어때요? 도움이 많이 되셨나요? ~~~~~~~


'Programming Languages > Golang(Go)' 카테고리의 다른 글

CentOS7 Golang(Go언어) 설치  (0) 2018.12.03

+ Recent posts